<img data-src="/path/to/image.jpg" alt="">
img {
opacity: 1;
transition: opacity 0.3s;
}

img[data-src] {
opacity: 0;
}

[].forEach.call(document.querySelectorAll('img[data-src]'), function(img) {
img.setAttribute('src', img.getAttribute('data-src'));
img.onload = function() {
img.removeAttribute('data-src');
};
});

 posted on 2016-04-19 00:08  jayruan  阅读(229)  评论(0编辑  收藏  举报