代码如下:


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

相关文章:

  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
  • 2022-12-23
  • 2022-02-16
  • 2021-12-09
  • 2021-05-22
猜你喜欢
  • 2021-07-31
  • 2022-12-23
  • 2021-10-01
  • 2021-11-14
  • 2022-12-23
  • 2021-09-05
  • 2021-09-19
相关资源
相似解决方案