【问题标题】:Splash Page display for 2s and then .fadeoutSplash Page 显示 2s 然后 .fadeout
【发布时间】:2015-10-30 17:13:53
【问题描述】:

我的网站有一个预加载器启动页面,我想在加载时显示它,并在 2 秒后淡出,显示下面的主要网站内容。

我有下面的代码,它可以很好地在窗口加载时显示启动页面,但我想用一个简单的 2 秒延迟替换它,以便它始终出现,即使对于那些超快速连接的人也是如此。目前,在快速连接时,它会过快地淡出。

谢谢。

HTML

<div class='preloader'>
    <div class="preloader-logo">Logo</div>
    <div class="preloader-loading-icon">Loading</div>
</div>

<main>Content goes here, should be hidden initially until fully loaded.</main>

CSS

.preloader {
    display: block;
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    top: 0;
    left: 0;
    z-index: 9999;
    background: rgba(255,102,51,1);
}

.preloader-logo {
    background: url(images/ui-sprite.svg) no-repeat 0 -300px;
    position: absolute;
    width: 140px;
    height: 58px;
    top: 50%;
    left: 50%;
    text-indent: -9999px;
}

.preloader-loading-icon {
    background: url(images/preloader-loading.svg) no-repeat 50%;
    text-indent: -9999px;
    position: relative;
    top: 50%;
    left: 50%;
    margin-top: 90px;
    width: 40px;
    height: 40px;
}

main { opacity: 0; } Hide main content to avoid flash before preloader initialises */

JS

/* Preloader Splash */
$(window).load(function(){
    $('#container').animate({opacity: 1},300);
    $('.preloader').fadeOut(500);
});

【问题讨论】:

    标签: javascript jquery css


    【解决方案1】:

    使用设置超时

    $(window).load(function(){
        setTimeout(function() {
            $('#container').animate({opacity: 1},300);
            $('.preloader').fadeOut(500);
        }, 2000);
    });
    

    【讨论】:

    • 嗨@mar​​ius_balaj,是实现相同效果的一种方法,但不是window $(window).load?我希望它立即发生,因为 2 秒的延迟应该足以处理加载方面的问题。我不想等待所有图像等加载?
    • 我不确定你想要实现什么,但可能你应该使用 $(document).ready 而不是 $(window).load
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多