第一个问题,请友善!
我已经能够让 Isotope 正常工作,但是当我尝试使用 RequireJS 将其与 jQuery 一起加载时,我似乎无法让它工作。
它肯定正在加载文件,因为我可以在开发工具栏的头部看到它们,所以路径很好。我对 isotopePkg
的作用感到困惑,他甚至说它是未定义的 (???)
这就是我的 app.js 的样子...
requirejs.config({
paths: {
'jquery' : ['//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',
'jquery-1.10.2.min'],
'isotope' : 'isotope.min'
},
shim: {
'isotope' : ['jquery']
}
});
require(['jquery', 'isotope'], function(jQuery, Isotope) {
jQuery('#container').isotope({
itemSelector: '.element'
});
});
有人有这个代码应该是什么样子的工作示例,或者对我在这里出错的地方有任何想法吗?
最佳答案
我遇到了同样的问题,在实时环境中要求同位素包正在请求其他模块。请参阅下面的代码和链接 isotope documentation有关如何使用 requirejs 实现 isotope 的进一步说明。
我意识到答案已经晚了,但希望这也可以帮助遇到此问题的任何人。
// require the require function
requirejs( [ 'require', 'jquery', 'path/to/isotope.pkgd.js' ],
function( require, $, Isotope ) {
// require jquery-bridget, it's included in isotope.pkgd.js
require( [ 'jquery-bridget/jquery.bridget' ],
function() {
// make Isotope a jQuery plugin
$.bridget( 'isotope', Isotope );
// now you can use $().isotope()
$('#container').isotope({...});
}
);
});
关于javascript - 将 Isotope v2 与 RequireJS 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20569293/