在modernizr/yepnope加载所有文件后执行回调 [英] Execute callback after modernizr/yepnope has loaded all files

查看:119
本文介绍了在modernizr/yepnope加载所有文件后执行回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行页面上的后续脚本之前,我需要加载许多测试条件和文件.是否在加载所有文件后触发回调?

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?

以下是这篇文章的建议,传达了我的意图,但实际上并不起作用.完整功能在1.js或2.js完成加载之前触发.

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.

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.

以某种方式将其嵌入或扩展Modernizr以构建完成"事件可能更直接.

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.

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); }
    }
]);

这篇关于在modernizr/yepnope加载所有文件后执行回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆