CSS, Lazy Loading, JavaScript, Tutorial, Javascript Tips.
}); We can wrap this code in a function and return the actual load callback. This makes it even easier. function lazyLoad(img) { var ratio = +img.getAttribute('data-height') / +img.getAttribute('data-width'); img.style.paddingTop = ratio * img.getBoundingClientRect().width + 'px'; var lazy = new