Skip to content

Instantly share code, notes, and snippets.

@navio
Last active January 31, 2016 17:04
Show Gist options
  • Save navio/8a3617a18716432d8376 to your computer and use it in GitHub Desktop.
Save navio/8a3617a18716432d8376 to your computer and use it in GitHub Desktop.
Lazy Loading.
function LL(){ //lazyload functionality;
var imageList = [];
function getImages(){
imageList.each(function(key,el){
var toSRC = el.attr("data-image");
el.attr("src",toSRC);
el.removeClass('lazyImage');
});
}
function addElements(els){
els.each(function(key,el){
imageList.push(el);
});
}
addElements($('.lazyImage'));
getImages();
}
var ll = new LL();
function isElementInViewport (el) {
if (el instanceof jQuery) { el = el[0]; }
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment