pop弹出 dialog对话框

pop弹出 dialog对话框

pop弹出 dialog对话框

 

XML/HTML Code
  1. <body onload="popup('<p>加载的时候弹出</p>')">  
  2. <h1 class="logo"><a href="http://www.freejs.net" title="freejs首页"><img src="../../images/logo.png" height="47" width="500" alt="freejs首页" /></a></h1>  
  3. <div id="main_demo">  
  4. <div align="center"><h2><a href="../../article_jquerywenzi_117.html">pop弹出 dialog对话框</a></h2></div>  
  5. <a href="javascript:popup('点击弹出')">点我!</a>  
  6.   
  7. <div id="dialog-overlay"></div>  
  8. <div id="dialog-box">  
  9.     <div class="dialog-content">  
  10.         <div id="dialog-message"></div>  
  11.         <a href="#" class="button">关闭</a>  
  12.     </div>  
  13. </div>  

 

JavaScript Code
  1. <script type="text/javascript">  
  2.   
  3. $(document).ready(function () {  
  4.   
  5.     // if user clicked on button, the overlay layer or the dialogbox, close the dialog    
  6.     $('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {       
  7.         $('#dialog-overlay, #dialog-box').hide();         
  8.         return false;  
  9.     });  
  10.       
  11.     // if user resize the window, call the same function again  
  12.     // to make sure the overlay fills the screen and dialogbox aligned to center      
  13.     $(window).resize(function () {  
  14.           
  15.         //only do it if the dialog box is not hidden  
  16.         if (!$('#dialog-box').is(':hidden')) popup();         
  17.     });   
  18.       
  19.       
  20. });  
  21.   
  22. //Popup dialog  
  23. function popup(message) {  
  24.           
  25.     // get the screen height and width    
  26.     var maskHeight = $(document).height();    
  27.     var maskWidth = $(window).width();  
  28.       
  29.     // calculate the values for center alignment  
  30.     var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());    
  31.     var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);   
  32.       
  33.     // assign values to the overlay and dialog box  
  34.     $('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();  
  35.     $('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();  
  36.       
  37.     // display the message  
  38.     $('#dialog-message').html(message);  
  39.               
  40. }  
  41.   
  42. </script>  

 


原文地址: http://www.freejs.net/article_jquerywenzi_117.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值