jquery easyui dialog不超出父容器以及随浏览器缩放

来源:互联网 发布:数据存储四种方式 编辑:程序博客网 时间:2024/05/10 05:08
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-type" content="text/html; charset=GBK">  
  4.      <title></title>  
  5.      <link rel="stylesheet" type="text/css" href="../sources/themes/default/easyui.css">  
  6.      <link rel="stylesheet" type="text/css" href="../sources/themes/icon.css">  
  7.      <script type="text/javascript" src="../sources/jquery-1.7.1.min.js"></script>  
  8.      <script type="text/javascript" src="../sources/jquery.easyui.min.js"></script>  
  9.   
  10.      <style type="text/css">  
  11.          body{width:100%;height:100%;}  
  12.          TABLE{WIDTH:100%;}  
  13.          #divDialog{padding:5px;}  
  14.      </style>  
  15.      <script type="text/javascript">  
  16.      function fixWidth(percent){  
  17.          return document.body.clientWidth * percent;  
  18.      }  
  19.      function openDivDialog(){  
  20.          $("#divDialog").dialog("open");  
  21.      }  
  22.      function closeDivDialog(){  
  23.          $("#divDialog").dialog("close");  
  24.      }  
  25.      $(function(){  
  26.          $(window).resize(function(){  
  27.            $("#divDialog").dialog({  
  28.             width:fixWidth(0.4)  
  29.            });  
  30.          });  
  31.          $("#divDialog").dialog({  
  32.              title:"对话框",  
  33.           collapsible:true,  
  34.           minimizable:true,  
  35.           maximizable:true,  
  36.           resizable:true,  
  37.           //modal:true, 是否是模式对话框  
  38.           width:fixWidth(0.4),  
  39.           height:200,  
  40.           //fitColumns:true,适应父容器的大小  
  41.           doSize:true,  
  42.   
  43.           toolbar:[{  
  44.                 text:"Add",  
  45.                 iconCls:"icon-add",  
  46.                 handler:function(){  
  47.                     alert("这是单击add按钮事件");  
  48.                 }  
  49.                  },"-",{  
  50.                 text:"save",  
  51.                 iconCls:"icon-save",  
  52.                 handler:function(){  
  53.                     alert("这是单击save按钮事件");  
  54.                  }  
  55.                 }],  
  56.   
  57.           buttons:[{  
  58.                 text:"Ok",  
  59.                 iconCls:"icon-ok",  
  60.                 handler:function(){  
  61.                     alert("这是单击ok按钮事件"+$("#divDialog"));  
  62.                 }  
  63.                  },{  
  64.                 text:"Cancle",  
  65.                 handler:function(){  
  66.                      alert("这是单击cancle按钮事件,关闭dialog");  
  67.                      $("#divDialog").dialog("close");  
  68.                 }  
  69.                 }],  
  70.             //事件绑定  
  71.             onMove:function(left,top){  
  72.             var right,bottom;  
  73.             //alert($("body").width()+"---"+left +"----"+ $("#divDialog").width()+"="+($("#divDialog").width()+left));  
  74.             var bodyWidth = $("body").width();  
  75.             var bodyHeight = $("body").height();  
  76.             var dialogwidth = $("#divDialog").width();  
  77.             var dialogHeight = $("#divDialog").height();  
  78.             if(left < 0){  
  79.                 $("#divDialog").dialog("move",{left:0,top:top});  
  80.             }else if((left + dialogwidth) > (bodyWidth - 50)){  
  81.                 right = bodyWidth - dialogwidth - 50;  
  82.                 $("#divDialog").dialog("move",{left:right,top:top});  
  83.             }  
  84.             if(top < 0){  
  85.                 $("#divDialog").dialog("move",{left:left,top:0});  
  86.             }else if(top > (bodyHeight - dialogHeight - 50 )){  
  87.                 bottom = bodyHeight - dialogHeight - 50;  
  88.                 $("#divDialog").dialog("move",{left:left,top:bottom});  
  89.             }  
  90.             }  
  91.          });  
  92.      });  
  93.      </script>  
  94.     </head>  
  95.     <body onresize="openDivDialog();">  
  96.         <h1>Dialog</h1>  
  97.      <div>  
  98.          <a href="#" onclick="openDivDialog();">open</a>  
  99.          <a href="#" onclick="closeDivDialog();">close</a>  
  100.      </div>  
  101.      <div id="divDialog" icon="icon-save">  
  102.         <TABLE>  
  103.            <TR align="center" bgColor="#dcdcdc">  
  104.                     <TD>用户编号</TD>  
  105.                     <TD>试用时间</TD>  
  106.                     <TD>转正时间</TD>  
  107.                     <TD>性别</TD>  
  108.                     <TD>姓名拼音</TD>  
  109.                     <TD>生日时间</TD>  
  110.                     <TD>民族</TD>  
  111.                     <TD>身高</TD>  
  112.                 </TR>  
  113.                 <TR>  
  114.                     <TD style="WIDTH: 75px">2000001</TD>  
  115.                     <TD>1997-3-13 0:00:00</TD>  
  116.                     <TD>1997-3-13 0:00:00</TD>  
  117.                     <TD>1</TD>  
  118.                     <TD>WZJ</TD>  
  119.                     <TD>1965-3-13 0:00:00</TD>  
  120.                     <TD></TD>  
  121.                     <TD>171</TD>  
  122.                 </TR>  
  123.                 <TR>  
  124.                     <TD style="WIDTH: 75px">2000045</TD>  
  125.                     <TD>2001-2-15 0:00:00</TD>  
  126.                     <TD>2001-3-15 0:00:00</TD>  
  127.                     <TD>0</TD>  
  128.                     <TD>WY</TD>  
  129.                     <TD>1978-8-5 0:00:00</TD>  
  130.                     <TD></TD>  
  131.                     <TD>162</TD>  
  132.                 </TR>  
  133.                 <TR>  
  134.                     <TD style="WIDTH: 75px">2000046</TD>  
  135.                     <TD>2001-2-23 0:00:00</TD>  
  136.                     <TD>2001-3-23 0:00:00</TD>  
  137.                     <TD>0</TD>  
  138.                     <TD>LQ</TD>  
  139.                     <TD>2001-2-23 0:00:00</TD>  
  140.                     <TD></TD>  
  141.                     <TD>171</TD>  
  142.                 </TR>  
  143.         </TABLE>  
  144.      </div>  
  145.     </body>  
  146. </html>  
 
原创粉丝点击