imagesLoaded – 检测网页中的图片是否加载

时间:2014-09-05 09:59:01   收藏:0   阅读:400

  imagesLoaded 是一个用于来检测网页中的图片是否载入完成的 JavaScript 工具库。支持回调的获取图片加载的进度,还可以绑定自定义事件。可以结合 jQuery、RequireJS 使用。

 

bubuko.com,布布扣

 

插件下载     效果演示

 

使用示例:

// element
imagesLoaded( document.querySelector(‘#container‘), function( instance ) {
  console.log(‘all images are loaded‘);
});
// selector string
imagesLoaded( ‘#container‘, function() {...});
// multiple elements
var 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 );

 

您可能感兴趣的相关文章

 

本文链接:imagesLoaded – 检测网页中的图片是否加载

编译来源:梦想天空 ◆ 关注前端开发技术 ◆ 分享网页设计资源

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!