js代码
//图片懒加载
window.onload = function() {
var Joe = document.getElementById('imgid');
var imgs = Joe.getElementsByTagName('img');
for (var i = 0; i < imgs.length; i++) {
(function(curImg) {
var tempImg = null;
tempImg = document.createElement('img');
console.log(curImg);
tempImg.src = curImg.dataset.src;
tempImg.onload = function(e) {
curImg.src = tempImg.src;
curImg.style.filter = 'blur(0px)';
}
})(imgs[i]);
}
}
html代码
<div id="imgid"><img class="lazyload" src="logo.jpg" data-src="图片地址" alt="" style="width: 100%" /></div>
评论 (0)