-
-
Save davidecavaliere/5937599 to your computer and use it in GitHub Desktop.
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
AUI().use( | |
'aui-base', | |
function(A) { | |
var WIN = A.getWin(); | |
var lazyLoadNode = A.all('.lazy-load'); | |
var lazyLoad = function() { | |
var currentScrollPos = WIN.get('docScrollY'); | |
var winHeight = WIN.get('innerHeight'); | |
if (winHeight == undefined) { | |
winHeight = document.documentElement.clientHeight; | |
} | |
lazyLoadNode.each( | |
function(item, index, collection) { | |
if (!item.hasClass('lazy-loaded')) { | |
var loadPos = item.getY() - winHeight; | |
if (currentScrollPos > loadPos) { | |
var datasrc = item.attr('datasrc'); | |
var src = item.attr('src'); | |
if (src != datasrc) { | |
item.attr('src', datasrc); | |
} | |
item.addClass('lazy-loaded'); | |
} | |
} | |
} | |
); | |
}; | |
if (!lazyLoadNode.isEmpty()) { | |
A.on('scroll', lazyLoad); | |
A.on('resize', lazyLoad); | |
lazyLoad(); | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool