本文介绍了不推荐使用Modernizr.load. Yepnope.js已弃用.怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Modernizr v3之前,我使用的是yepnope.js
Prior to Modernizr v3, I was using yepnope.js
Modernizr.load和yepnope.js均已弃用.我们现在如何有条件地调用样式表或javascript文件?
Modernizr.load and yepnope.js have both been deprecated. How do we conditionally call stylesheets or javascript files now?
与Modernizr v2.5.3兼容的示例:
Example that worked with Modernizr v2.5.3:
Modernizr.load({
test: Modernizr['object-fit'],
nope: ['./dist/scripts/object-fit.js'],
complete: function(){
if (!Modernizr['object-fit']) {
jQuery(".poster img").imageScale({
scale: "best-fill",
rescaleOnResize: true
});
}
}
});
推荐答案
有新语法和功能名称均为小写.您可以将其与 jQuery的getScript方法结合.
There's a new syntax and the feature names are all lowercase. You can combine that with jQuery's getScript method.
看起来像这样:
if (Modernizr.objectfit){
jQuery.getScript("./dist/scripts/object-fit.js")
//it worked! do something!
.done(function(){
console.log('js loaded');
})
//it didn't work! do something!
.fail(function(){
console.log('js not loaded');
});
} else {
jQuery(".poster img").imageScale({
scale: "best-fill",
rescaleOnResize: true
});
}
这篇关于不推荐使用Modernizr.load. Yepnope.js已弃用.怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!