สร้าง popup message ด้วย jquery อย่างง่าย

เขียนเมื่อ 10 ปีก่อน โดย Ninenik Narkdee
jquery popup

คำสั่ง การ กำหนด รูปแบบ ตัวอย่าง เทคนิค ลูกเล่น การประยุกต์ การใช้งาน เกี่ยวกับ jquery popup

ดูแล้ว 19,791 ครั้ง


เนื้อหานี้เป็นแนวทางอย่างง่าย สามารถประยุกร์หรือดัดแปลง
ได้ตามความเหมาะสม 
เป็นดัดแปลงเพิ่มเติมจาก เนื้อหา
 
การทำให้หน้าเว็บของเราสามารถดูได้อย่างเดียว 
https://www.ninenik.com/content.php?arti_id=56 via @ninenik

โค้ดทั้งหมด

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">  
 html {   
        height: 100%;   
        }   
body {   
    background: #FFF;   
    padding: 0;   
    margin: 0;   
    width: 100%;   
    height: 100%;  
 }  
#overlay {   
  	background:#000;
	width:100%;
	height:100%;
	z-index:80000;
	top:0px;
	left:0px;
	position:fixed;
    opacity: .5;   
    filter: alpha(opacity=50);   
    -moz-opacity: .5;  
	display:none;
}   
.msg_show{
	position:fixed;
	z-index:90000;
	margin:auto;
	width:500px;
	height:150px;
	top: 50%;
	left: 50%;
	margin-top: -100px;
	margin-left: -250px;
	border-radius: 36px 36px 36px 36px;
	-moz-border-radius: 36px 36px 36px 36px;
	-webkit-border-radius: 36px 36px 36px 36px;
	border: 0px solid #000000;	
	background-color:#9C9;
	text-align:center;
	display:none;
}
</style> 
</head>

<body> 
<div style="margin:auto;width:1000px;">
<a class="show_box" href="javascript:void(0);">show</a>
<!--เนื้อหาภายในเว็บ-->  <br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
test test<br />test test<br />
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>    
<script type="text/javascript">
$(function(){
	$(".show_box").click(function(){
		$("#overlay").fadeToggle("",function(){ // แสดงส่วนของ overlay
			$(".msg_show").slideToggle("",function(){ // แสดงส่วนของ เนื้อหา popup
				if($(this).css("display")=="block"){		// ถ้าเป็นกรณีแสดงข้อมูล 
				//	หากต้องการดึงข้อมูลมาแสดง แบบ ajax
				//	สามารถดัดแปลงจากโค้ดนี้ได้		
				//	$(".msg_data").load("data.php");	
				//		หรือ
				//	$.post("data.php",{},function(data){
				//		$(".msg_data").html(data);
				//	});
				}
			});
		});
	});
});
</script>
<div class="msg_show">
<a class="show_box" href="javascript:void(0);">Close</a>
<div class="msg_data">
<!--เนื้อหาใน popup message-->
</div>
</div>
<div id="overlay"></div> 
</body>  
</html>


ตัวอย่าง

show
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
test test
 
 
 


กด Like หรือ Share เป็นกำลังใจ ให้มีบทความใหม่ๆ เรื่อยๆ น่ะครับ





Tags:: jquery popup







URL สำหรับอ้างอิง





คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )







เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ