2012-07-30 27 views
1

我有一个divimg这需要围绕在窗已经扩展jQuery的功能,为了做到这一点使用此功能:页面加载之前居中容器使用jQuery

jQuery.fn.center = function() { 
       this.css("position","absolute"); 
       this.css("top", Math.max(0, (($(window).height() - this.outerHeight())/2) +$(window).scrollTop()) + "px"); 

       this.css("left", Math.max(0, (($(window).width() - this.outerWidth())/2) + $(window).scrollLeft()) + "px"); 

       return this; 
      } 

此功能完美但唯一的问题是图像首先加载它的默认位置,然后移动到中心。如何让图像直接在页面加载中心看到?

编辑:这里就是我的意思:www.foxteam.net/portfolio.php

回答

1

我真的需要看到,调用这个函数来帮助你,但这里有一个快速的建议代码。

display:none;和链您.fadeIn()函数首先渲染IMG .center() 后或使用回调使其同步。

这样,即使在显示图像之前,您也会将图像居中。

相关问题