简体   繁体   English

启动画面显示2秒,然后按.fadeout

[英]Splash Page display for 2s and then .fadeout

I have a preloader splash page for my website that I would like to display upon load, and fade out after 2s, revealing the main website content below. 我的网站有一个预加载器启动页面,我希望在加载时显示该页面,并在2秒后消失,以显示下面的主要网站内容。

I have the below code, which work well to display the splash page upon window load, but I want to replace this with a simple 2s delay, so that it always appear, even for those on super fast connections. 我有以下代码,可以很好地在窗口加载时显示初始页面,但是我想用一个2s的简单延迟来替换它,以便即使对于超快速连接的用户也总是显示它。 Currently it is fading out too quickly when on a fast connection. 当前,在快速连接时它褪色的速度太快了。

Thanks. 谢谢。

HTML 的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 的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 JS

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

Use setTimeout 使用setTimeout

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM