imagesLoaded 是一个用于来检测网页中的图片是否载入完成的 工具库。支持回调的获取图片加载的进度,还可以绑定自定义事件。可以结合 jQuery、RequireJS 使用。
使用示例:
// elementimagesLoaded( document.querySelector('#container'), function( instance ) { console.log('all images are loaded');});// selector stringimagesLoaded( '#container', function() {...});// multiple elementsvar posts = document.querySelectorAll('.post');imagesLoaded( posts, function() {...});
绑定自定义事件:
var imgLoad = imagesLoaded( elem );function onAlways( instance ) { console.log('all images are loaded');}// bind with .on()imgLoad.on( 'always', onAlways );// unbind with .off()imgLoad.off( 'always', onAlways );
您可能感兴趣的相关文章
本文链接:
编译来源: