简体   繁体   English

在modernizr / yepnope加载所有文件后执行回调

[英]Execute callback after modernizr/yepnope has loaded all files

I have a number of test conditions and files to load before I run the follow up scripts on my page. 在运行页面上的后续脚本之前,我需要加载许多测试条件和文件。 Is there a way to fire a callback after ALL my files are loaded? 是否在加载所有文件后触发回调?

The following is suggested by this post and communicates my intent but does not actually work. 这篇文章建议了以下内容,传达了我的意图,但实际上不起作用。 The function in the complete is firing before 1.js or 2.js has finished loading. 完整功能在1.js或2.js完成加载之前触发。

Modernizr.load([
    {
        test: App.isSmallScreen,
        yep:  '1.js',
        nope: '2.js'
    },
    {
        test: App.isTouch,
        yep: '3.js'
    },
    {
        test: Modernizer.csstransitions,
        nope:4.js
    },
    {
        complete: animationInit
    }
]);

Apologies in advance for such a cheap trick but this was the best I could come up with. 提前道歉这么便宜的技巧,但这是我能想到的最好的方法。 It could definitely be improved though. 不过,绝对可以改善它。

It would probably be fairly straightforward to embed this or extend Modernizr to build in a "finished" event in some way to do this more cleanly. 将其嵌入或扩展Modernizr以某种方式“完成”事件以更干净地进行此操作可能非常简单。

var completed = []
var complete = function(i) {
  completed.push(i)
  if (completed.length === 3) animationInit();
}

Modernizr.load([
    {
        test: App.isSmallScreen,
        yep:  '1.js',
        nope: '2.js',
        complete: function() { complete(1); }
    },
    {
        test: App.isTouch,
        yep: '3.js'
        complete: function() { complete(2); }
    },
    {
        test: Modernizer.csstransitions,
        nope:4.js
        complete: function() { complete(3); }
    }
]);

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

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