爲什麼return false
退出$.each
循環下面?
var Items = {
"5340071": {
"alt": "Sample text"
},
"5333539": {
"alt": "Sample text"
},
// Etc.
};
var viewportBottom = $(window).height() + $(window).scrollTop();
$.each(Items, function(itemId, objItem) {
$("<img src='/img/1503/4/" + itemId + ".jpg?h=150'>").on('load', function() {
$(document.body).append($(this));
var imageTop = $(this).offset().top;
if (imageTop > viewportBottom) {
console.log('Exit loop'); // Text is printed in console
return false; // This should break the $.each loop, but it doesn't
}
});
});
請指教。
@ T.J.Crowder它在'for'中工作,我假設它適用於'$ .each' :) – guradio
@guradio:它們是完全不同的東西。 –