UNPKG

hexo-lazyload-image

Version:

a hexo plugin which is used to have all images support lazyload, with the help of this functionality, it will improve lots of the loading proformance.

11 lines 490 B
window.addEventListener('load', function(){ var imgRegex = /\.(gif|jpg|jpeg|tiff|png)$/i; var base64ImgRegex = /^data:image\/[a-z\d\-\.\+]+;base64,/; var images = Array.prototype.slice.call(document.querySelectorAll('img[data-original]')); images.forEach(function(img) { var parentNode = img.parentNode; if(parentNode.tagName === 'A' && (imgRegex.test(parentNode.href) || base64ImgRegex.test(parentNode.href))) { parentNode.href = img.dataset.original; } }); });