Last active
August 29, 2015 14:02
-
-
Save azisaka/99e4f782a37c57709ed2 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 div1 = $("#the-div1"); | |
var div2 = $("#the-div2"); | |
var div3 = $("#the-div3"); | |
var aziScroll = new AziScroll(); | |
aziScroll.addEvent(1000, div1, function(element) { element.addClass("x") }); | |
aziScroll.addEvent(2000, div2, function(element) { element.addClass("y") }); | |
aziScroll.addEvent(3000, div3, function(element) { element.addClass("z") }); | |
var onScroll = function() { | |
var positionTop = $(this).scrollTop(); | |
aziScroll.onScroll(positionTop); | |
}; | |
$(document).bind("scroll", onScroll); |
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
function AziScroll() { | |
this.events = []; | |
}; | |
AziScroll.prototype.addEvent = function(xPosition, element, callback) { | |
var event = new AziScrollEvent(xPosition, element, callback); | |
this.events.push(event); | |
}; | |
AziScroll.prototype.onScroll = function(positionTop) { | |
var event; | |
for(var x = 0; x < this.events.length; x++) { | |
event = this.events[x]; | |
if(positionTop >= event.xPosition) { | |
event.happens(); | |
} | |
} | |
}; | |
function AziScrollEvent(xPosition, element, callback) { | |
this.xPosition = xPosition; | |
this.element = element; | |
this.callback = callback; | |
}; | |
AziScrollEvent.prototype.happens = function() { | |
this.callback(this.element); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment