0

我正在开发一个网站,该网站使用 jquery animate 函数在加载时从左上角展开网站。我实际上并不是为该功能编写代码的人,所以我对它并不太熟悉。它在某一时刻确实有效,但目前它似乎根本不起作用。我知道 .js 文件正在加载并正在运行,因为其中的第一段代码是显示“正在加载页面”消息的时间延迟。但是它只是显示已经加载的页面,而不是动画从左上角出现并滑入的页面。我也包括了 CSS 和标记,尽管我不相信这就是问题所在。任何帮助,将不胜感激!谢谢!

注意:我们使用的是 Jquery 版本 1.7.2

CSS:

 #builder
    {
        position:relative;
        min-height:100%;
        min-width:100%;
        z-index:999;
    }

JavaScript:

function hideIt() {

    document.getElementById("wait").style.display = "none";

}

setTimeout("hideIt()", 1000);

function showIt() {

    document.getElementById("builder").style.display = "block";
}

setTimeout("showIt()", 2500);

function build() {
    $(document).ready(function () {

        $("#builder").animate({ height: '0%', width: '0%' }, 1);
        $("#builder").animate({ height: '100%', width: '100%' }, 2000);


    });
}

标记:

<body onLoad="build()">
<img src="wait.gif" id="wait" style="display:block;" />

wait.gif 只是一张图片,上面写着“页面正在加载”......

页面包含在以下内容中:

<div id="builder" align=center style="display:none;">
4

3 回答 3

1

如果 #builder 元素在显示之前被隐藏 2.5 秒,则动画将在元素显示时完成。删除 body onLoad 上的内联函数并尝试:

function hideIt() {
    $("#wait").hide();
}

function showIt() {
    $("#builder").show(2000); //should do somewhat the same as animating from the top left
}

$(function() {
    setTimeout(hideIt, 1000); //no need to quote the functions and eval them
    setTimeout(showIt, 2500);
});

要不就

$("#wait").delay(1000).hide(10);
$("#builder").delay(2500).show(2000)
于 2012-07-03T01:02:55.460 回答
0

尝试像这样调整您的代码:

$(document).ready(function() {
    $('#wait').hide(1000, function(){  // hide the #wait
        $("#builder").show().animate({ // then show, then animate #builder
            height: '100%',
            width: '100%'
        }, 2000);
    });
});

旁注:请记住,当您使用百分比和包含 的元素时#builder,还需要设置它的高度和宽度。

于 2012-07-03T00:52:24.730 回答
0

show()很可能在你被调用之前它就已经被动画化了。所以到它显示的时候,动画就完成了。

于 2012-07-03T00:52:42.563 回答