1

我有一个需要以窗口为中心的一个div和一个。我img已经扩展了 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

4

1 回答 1

1

我实际上需要查看调用此函数的代码来帮助您,但这里有一个快速建议。

首先渲染 imgdisplay:none;并在之后链接您的.fadeIn()函数,.center() 或者使用回调使其同步。

这样,您甚至在显示图像之前就将其居中。

于 2012-07-30T12:26:30.143 回答