第一个问题所以请你好!
我已经能够让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'
});
});
有没有人有这个代码应该是什么样子的工作示例,或者对我在哪里出错有任何想法?
答案 0 :(得分:4)
我遇到了同样的问题,即在现场环境中要求同位素包请求其他模块。请参阅下面的代码并链接isotope documentation以获取有关如何使用requirejs实施同位素的进一步说明。
我意识到答案很晚,但希望这也可以帮助那些遇到这个问题的人。
// 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({...});
}
);
});