教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jquery实现弹出层完美居中效果

jquery实现弹出层完美居中效果

发布时间:2014-07-12   编辑:jiaochengji.com
本篇文章主要是对jquery弹出层居中效果的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

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

您可能感兴趣的文章:
jquery实现弹出层完美居中效果
jquery实现点击弹出层效果的简单实例
Jquery+CSS3实现一款简洁大气带滑动效果的弹出层
jquery ui dialog实现弹窗特效的思路及代码
jquery实现居中弹出层代码
jQuery弹出窗口完整代码(居中,居左,居右)
Jquery 弹出窗口居中效果的实现代码
基于jquery实现的一个选择中国大学的弹框 (数据、步骤、代码)
【精品推荐】web开发人员应该知道的31个jQuery模态对话框
css实现在div水平垂直居中与图片水平居中的效果

关键词: jquery  弹出层   
[关闭]
~ ~