jquery实现弹出层完美居中效果
程序员文章站
2023-10-27 21:53:28
p>jquery实现弹出层完美居中效果
. 代码如下:
showdiv($("#pop"));
function showdiv(obj){...
p>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
});
}