您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

jquery实现弹出层完美居中效果

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 本篇文章主要是对jquery弹出层居中效果的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

jquery实现弹出层完美居中效果    代码如下: 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     });   }