jquery弹出层完美居中

mac2022-06-30  18

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        });  }

 

转载自:http://www.w3cfuns.com/blog-5396619-5395246.html

转载于:https://www.cnblogs.com/-gap/archive/2012/08/18/2645083.html

相关资源:JS、JQuery、CSS DIV实例大全
最新回复(0)