我已经创建了一个包含页面上所有图像的URL的数组,然后将这个数组发送到一个函数,该函数依次加载每个图像。然后,页面加载布局。然而,我正在收到以下错误:
Uncaught TypeError: object is not a function任何帮助都很感激
JS :
$(document).ready(function () {
preLoadImages();
useIsotope();
});
function useIsotope() {
var $container = $('#work').isotope({
filter: "*"
});
$('#control ul li a').click(function () {
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
}
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
$('<img/>')[0].src = this;
});
}
function preLoadImages() {
var imageArray = new Array();
$('.imgWrapper a img').each(function (index) {
imageArray.push(this.src)
});
console.log(imageArray)
preLoad(imageArray) // HERE IS THE ERROR
}发布于 2015-03-15 22:39:13
使用preload(imageArray)而不是preLoad(imageArray)。
JavaScript是区分大小写的。(来源)
发布于 2015-03-15 22:41:29
我看不出您评论的地方有错误,但这看起来像是错误。
您正在设置$container = $('#work').isotope({ filter:"*“});
然后试着打电话
$container.isotope({ filter: selector });我想你应该这样写。
function useIsotope(){
var $container = $('#work');
$container.isotope({ filter: "*" });
$('#control ul li a').click(function(){
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
}更新在阅读了@Guy的答案之后,我也看到了preload v. preLoad错误。
https://stackoverflow.com/questions/29066902
复制相似问题