Home >Web Front-end >JS Tutorial >jquery achieves perfect centering effect of pop-up layer_jquery

jquery achieves perfect centering effect of pop-up layer_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:57:451140browse

jquery achieves the perfect centering effect of the popup layer

Copy the code The code is as follows:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn