SoFunction
Updated on 2025-02-28

Js control pop-up window realizes centered display at any resolution


//The height of the window
var windowHeight;
//The width of the window
var windowWidth;
//The height of the pop-up window
var popHeight;
//The width of the pop-up window
var popWidth;
//The height of the scroll bar scrolling
var scrollTop;
//The width of scroll bar scrolling
var scrollleft;
//Delay time
var timeout;
function init(){
//Get the height of the window
windowHeight=$(window).height();
//Get the window width
windowWidth=$(window).width();
//Get the height of the pop-up window
popHeight=$(".window").height();
//Get the pop-up window width
popWidht=$(".window").width();
//Get the height of the scroll bar
scrollTop=$(window).scrollTop();
//Get the width of the scroll bar
scrollleft=$(window).scrollLeft();
}
//Define the Close window
function closeWindow(){
$(".title img").click(function (){
$(this).parent().parent().hide("slow");

});

}
//Define the method of pop-up window
function popcenterWindow(){
//Clear the last delay first
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=(windowHeight-popHeight)/2+scrollTop;
var popX=(windowWidth-popWidht)/2+scrollleft;
$("#center").animate({top:popY,left:popX},300).show("slow");},300);
closeWindow();
}
function popleftWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=windowHeight+scrollTop-popHeight-10;
var popX=scrollleft-5;
$("#left").animate({top:popY,left:popX},300).show("slow");},300);
closeWindow();
}
function poprightWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=windowHeight-popHeight+scrollTop-10;
var popX=windowWidth-popWidht+scrollleft-10;
$("#right").animate({top:popY,left:popX},300).show("slow");},300);
closeWindow();
}