简体   繁体   English

如何使jQuery加载屏幕视图至少3秒钟?

[英]How to make jQuery loading screen view at least 3 seconds?

I just created my own loading screen with this code: 我刚刚使用以下代码创建了自己的加载屏幕:

HTML CODE: <div class="loader"></div>

CSS CODE: .loader {
            position: fixed;
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            z-index: 9999;
            background: url(../Images/page-loader.gif) 50% 50% no-repeat rgb(249,249,249);}

jQuery CODE: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>



AND
             $(window).load(function() {
             $(".loader").fadeOut("slow");})

Each time the page loads, the loading screen only displays for a fraction of a second. 每次页面加载时,加载屏幕仅显示一秒钟的时间。 Im trying to display the loading screen at least 3 seconds. 我试图显示加载屏幕至少3秒钟。 What jQuery code should I add? 我应该添加什么jQuery代码?

use setInterval 使用setInterval

$(window).load(function() {
  setInterval(function() {
    $(".loader").fadeOut("slow")
  }, 3000);
});

To delay the fadeOut action you can use the delay() function in jQuery https://api.jquery.com/delay/ 要延迟fadeOut操作,可以在jQuery https://api.jquery.com/delay/中使用delay()函数。

This will delay your fadeout by 3s (3000ms). 这将使淡入延迟3秒钟(3000毫秒)。

$(window).load(function() {
  $(".loader").delay(3000).fadeOut("slow");
})

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

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