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

WBOY
Release: 2016-05-16 16:57:45
Original
1091 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template