这是您的问题区域:
jQuery.extend(jQuery, {
imagesToLoad: 0,
问题是这个变量是全局/共享的(jQuery.imagesToLoad
),所以稍后检查:
if(jQuery.loadedImages.length >= jQuery.imagesToLoad){
取决于此插件不会同时被调用两次,否则 if 检查会变得疯狂,因为您稍后会在代码中调用它:
$.preloadImages({
urls: [nextImage],
该计数下降到 1,使得if
评估为true
不仅在最后一个图像上,而且在第一个图像之后的所有图像上(由于回调运行时,它在时间上重叠),这会导致complete
回调触发many多次,而不只是一次,所以这段代码:
$.preloadImages({
urls: preloadImages,
complete: function() { showProperty(property); }
});
...看到了complete
函数运行many次,所以你开始了many同时间隔(这就是为什么你看到console.log('show property called' + property.slug)
在日志中执行了很多次)。
简短修复:更换preloadImages
代码版本不使用全局变量:)