jquery实现弹出层完美居中效果_Javascript教程-查字典教程网
jquery实现弹出层完美居中效果
jquery实现弹出层完美居中效果
发布时间:2016-12-30 来源:查字典编辑
摘要:jquery实现弹出层完美居中效果复制代码代码如下:showDiv($("#pop"));functionshowDiv(obj){$(ob...

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

});

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类