Loading Scripts Using Modernizr… Not Working

╄→гoц情女王★ 提交于 2019-12-10 18:15:08

问题


I'm having problems trying to load scripts using the Modernizr version of yepnope and can't get my head around why they are different. If I load the scripts using yep nope it works fine:

<script type="text/javascript" src="/js/yepnope.1.0.2-min.js"></script>
<script type="text/javascript">
yepnope([  
    '/js/fancy-box-2.0.4/jquery.fancybox.css',  
    '/js/jquery-1.7.min.js',  
    '/js/jquery.form-defaults.js',  
    '/js/jquery.cycle.all.js',  
    '/js/jquery.easing.1.3.js',  
    '/js/fancy-box-2.0.4/jquery.fancybox.js',  
    '/js/functions.js',  
    'http://use.typekit.com/uoy8fub.js'
]); 
</script>

But if I trying using the Modernizr packaged version of yep nope I can't get anything to load... Help?

<script type="text/javascript" src="/js/modernizr-2.0.6.js"></script>
<script type="text/javascript">
Modernizr.load([  
    '/js/fancy-box-2.0.4/jquery.fancybox.css',  
    '/js/modernizr-2.0.6.js',  
    '/js/jquery-1.7.min.js',  
    '/js/jquery.form-defaults.js',  
    '/js/jquery.cycle.all.js',  
    '/js/jquery.easing.1.3.js',  
    '/js/fancy-box-2.0.4/jquery.fancybox.js',  
    '/js/functions.js',  
    'http://use.typekit.com/uoy8fub.js'
]); 
</script>

回答1:


UPDATE: Modernizr.load has been deprecated in version 3.0 in favour of using YepNope.js directly.

It's worth noting that Modernizr.load just uses the yepnope library and they are interchangeable. e.g.

yepnope({
  test : Modernizr.geolocation,
  yep  : 'normal.js',
  nope : ['polyfill.js', 'wrapper.js']
});

Modernizr.load({
  test : Modernizr.geolocation,
  yep  : 'normal.js',
  nope : ['polyfill.js', 'wrapper.js']
});

For yours, try:

Modernizr.load({
    load: [  
        '/js/fancy-box-2.0.4/jquery.fancybox.css',  
        '/js/jquery-1.7.min.js',  
        '/js/jquery.form-defaults.js',  
        '/js/jquery.cycle.all.js',  
        '/js/jquery.easing.1.3.js',  
        '/js/fancy-box-2.0.4/jquery.fancybox.js',  
        '/js/functions.js',  
        'http://use.typekit.com/uoy8fub.js'
    ]
}); 



回答2:


Modernizr needs a test to decide what to do. Generally Modernizr.load is used to load polyfills so you should read this: http://www.modernizr.com/docs/#load



来源:https://stackoverflow.com/questions/8909862/loading-scripts-using-modernizr-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!