zoukankan      html  css  js  c++  java
  • jquery居中窗口-页面加载直接居中

    <!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>
      <title> new document </title>
      <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <link rel="stylesheet" type="text/css" href="" />
      <style type="text/css"></style>
      <script type="text/javascript" src="jquery-1.7.1.min.js "></script>
     </head>
     <body>
     <div id="pop" style="200px;height:100px;border:1px solid red;background-color:red;">
     我是测试文字
     </div>
    <script type="text/javascript">
      showDiv($("#pop"));
    function showDiv(obj){
     $(obj).show();
     center(obj);
     $(window).scroll(function(){
      center(obj);
     });
     $(window).resize(function(){
      center(obj);
     });
    }
    
    function center(obj){
     var windowWidth = document.documentElement.clientWidth;  
     var windowHeight = document.documentElement.clientHeight;  
     var popupHeight = $(obj).height();  
     var popupWidth = $(obj).width();   
     $(obj).css({  
      "position": "absolute",  
      "top": (windowHeight-popupHeight)/2+$(document).scrollTop(),  
      "left": (windowWidth-popupWidth)/2  
     }); 
    }
    </script>
     </body>
    </html>
  • 相关阅读:
    c# winform DataGridView导出数据到Excel中,可以导出当前页和全部数据
    水晶报表动态加载图片(签名)
    第1章 开启Threejs之旅(一)
    Python中@contextmanager的用法
    Systemd
    Python中with的用法
    systemctl的配置和使用
    /*CS5460_Note_1*/
    Just try the code
    MCP2515无BUG版本驱动(C文件)
  • 原文地址:https://www.cnblogs.com/yangzailu/p/6474486.html
Copyright © 2011-2022 走看看