Last active
January 31, 2016 17:04
-
-
Save navio/8a3617a18716432d8376 to your computer and use it in GitHub Desktop.
Lazy Loading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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