【问题标题】:Add timeout to waitForImages为 waitForImages 添加超时
【发布时间】:2015-04-16 15:09:07
【问题描述】:

我正在尝试创建一个加载页面,等待所有图像都加载完毕。这是一个很棒的插件,但我想知道是否有办法为其添加超时,这样如果加载速度非常快,加载页面就不会只是在你面前闪烁......

这是我写的,但它似乎不起作用。因此,如果所有图像都已加载并且是在 3 秒后,则摆脱加载页面。如果有人有任何建议,将不胜感激!谢谢!

var timeout = false;

setTimeout(function() {
    timeout = true;
    console.log("TIMEOUT!");
}, 3000);

$("html").css({overflow: 'hidden' })


$('html').waitForImages({
    waitForAll: true,
    finished: function() {
       if (timeout == true) {
           $('#loading').css({display: 'none'});
           $("html").css({overflow: 'scroll' });
           $('html').unbind('touchmove');
       }
    }  

});

【问题讨论】:

    标签: jquery timeout waitforimages


    【解决方案1】:

    我会稍微修改你的代码:

    var timeout = false;
    var loadedimages = false;
    
    setTimeout(function() {
        console.log("TIMEOUT!");
        if (loadedimages == true) hideloadingdiv();
        else timeout = true;
    
    }, 3000);
    
    $("html").css({overflow: 'hidden' })
    
    
    $('html').waitForImages({
        waitForAll: true,
        finished: function() {
           if (timeout == true) {
               hideloadingdiv();
           }
           else
           {
               loadedimages = true;
           }
        }  
    });
    
    function hideloadingdiv()
    {
        $('#loading').css({display: 'none'});
        $("html").css({overflow: 'scroll' });
        $('html').unbind('touchmove');
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 2015-10-22
      • 2012-03-04
      • 2012-02-22
      • 2013-01-14
      • 1970-01-01
      • 2011-11-30
      • 2014-10-16
      • 1970-01-01
      相关资源
      最近更新 更多