我正在使用这个项目:https ://github.com/cowboy/jquery-throttle-debounce
我的代码是-sorta-working,但去抖被忽略了。因此,在每次图像加载时都会调用瀑布函数,但没有考虑 2 秒的延迟。没有显示错误。
实现这一点的正确方法是什么?我一直在摆弄这个 3 个小时,但找不到解决方案。
(function($) {
$(document).ready(function(e) {
var $waterfall = $('.waterfall');
if ($waterfall.length) {
$waterfall.waterfall({});
}
// sort the waterfall when images are loaded
var $waterfall_images = $waterfall.find('img');
$waterfall_images.each(function(j, image) {
var $img = $(image);
$img.load(function() {
$.debounce(2000, $waterfall.waterfall('sort'));
});
});
});
})(jQuery);
<ul class="waterfall">
<li class="waterfall-item">
<a href="hidden link" title="hidden title">
<img alt="hidden alt" title="hidden title" data-srcset="hidden in this example" data-src="also hidden in this example" src="still hidden in this example" data-sizes="(min-width:440px) 300px, 95vw" class=" lazyloaded" sizes="(min-width:440px) 300px, 95vw"
srcset="think I'll hide this one too">
<span class="waterfallImgOverlay"></span>
</a>
</li>
</ul>