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

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

 

 

插件下载     效果演示

 

使用示例:

1
2
3
4
5
6
7
8
9
// 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() {...});

绑定自定义事件:

1
2
3
4
5
6
7
8
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 – 检测网页中的图片是否加载

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

posted @   梦想天空(山边小溪)  阅读(9766)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示