imagesLoaded 是一个用于来检测网页中的图片是否载入完成的 JavaScript 工具库。支持回调的获取图片加载的进度,还可以绑定自定义事件。可以结合 jQuery、RequireJS 使用。
使用示例:
// 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 );
您可能感兴趣的相关文章
- Web 开发中很实用的10个效果【源码下载】
- 精心挑选的优秀jQuery Ajax分页插件和教程
- 12个让人惊叹的的创意的 404 错误页面设计
- 让网站动起来!12款优秀的 jQuery 动画插件
- 十分惊艳的8个 HTML5 & JavaScript 特效
本文链接:imagesLoaded – 检测网页中的图片是否加载
编译来源:梦想天空 ◆ 关注前端开发技术 ◆ 分享网页设计资源
时间: 2024-08-24 06:31:23