Created
January 6, 2010 08:15
-
-
Save amclean/270129 to your computer and use it in GitHub Desktop.
This file contains 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
var scrollLoader = function(){ | |
return{ | |
elements: [], | |
winHeight: window.innerHeight ? window.innerHeight : $(window).height(), | |
threshHold: 150, | |
init: function(){ | |
this.setElementsPosition(); | |
$(window).bind('scroll',_.bind(scrollLoader.checkViewPort,this)); | |
this.checkViewPort.lastChecked = 0; | |
this.checkViewPort.busy = false; | |
this.checkViewPort(); | |
}, | |
setElementsPosition: function(){ | |
var els = $('.dl'); | |
var me = this; | |
var scrollTop = window.scrollY + this.threshHold; | |
els.each(function(i){ | |
var el = $(this); | |
var top = parseInt(el.offset().top)+i; | |
me.elements[top] = el; | |
}); | |
}, | |
checkViewPort: function(){ | |
if(this.checkViewPort.busy === true){ | |
return; | |
} | |
this.checkViewPort.busy = true; | |
var scrollTop = window.scrollY + this.threshHold + this.winHeight; | |
var me = this; | |
if(me.elements.length == 0){ | |
$(window).unbind('scroll'); | |
return; | |
} | |
for(var i = scrollTop; i > this.checkViewPort.lastChecked; i--){ | |
if(me.elements[i] instanceof Object){ | |
var img = me.elements[i].find('img'); | |
var a = document.createAttribute('src'); | |
a.value = img.attr('rel'); | |
img[0].setAttributeNode(a) | |
me.elements[i] = null; | |
} | |
} | |
this.checkViewPort.lastChecked = scrollTop; | |
this.checkViewPort.busy = false; | |
} | |
} | |
}(); | |
scrollLoader.init(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment