css code สำหรับกล่องข้อความ จัดรูปแบบตามต้องการ
1 2 3 4 5 6 7 8 9 10 11 | <style type= "text/css" > div.alertBox{ border : 5px solid #33CC00 ; background-color : #F5FEED ; width : 300px ; margin : auto ; height : 75px ; text-align : center ; font-size : 12px ; } </style> |
HTML ปุ่ม สำหรับตัวอย่าง code
1 | < input type = "button" name = "btAddOverlay" id = "btAddOverlay" value = "ตัวอย่างคลิก" /> |
javascript code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <script type= "text/javascript" > google.load( "jquery" , "1.3.2" ); </script> <script type= "text/javascript" > $( function (){ var OverlayObj= "<div class='overlay'><div class='alertBox'></div></div>" ; $( "#btAddOverlay" ).click( function (){ $(document.body).prepend(OverlayObj); $( "div.overlay" ).css({ position: "absolute" , top:0, left: 0, background: "#000" , width: "100%" , height:$(document).height(), opacity:.7 }); $( "div.alertBox" ).animate({ marginTop:150 },500).html( "<br>จัดรูปแบบกล่องข้อความ นี้ใน css class<br>Click to close" ); $( "div.alertBox" ).bind( 'click' , function (){ $( "div.overlay" ).fadeOut( "fast" ); }); }); }); </script> |
ตัวอย่างคลิก ตัวอย่าง