Created
March 15, 2012 02:15
-
-
Save johnkpaul/2041247 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
Plugin.prototype.init = function(){ | |
var self = this, | |
offset = $(this.element).offset(); //need to inject test data here | |
$(window).scroll(function(event){ | |
//event.target is usually the object that jQuery was called on | |
//I could have used this or $(window), but neither is testable | |
if(elementIsOutsideViewport(event.target, offset)){ | |
self.elementScrolledOff(); | |
} | |
else{ | |
self.elementScrolledOn(); | |
} | |
}); | |
} | |
Plugin.prototype.elementScrolledOn = function(){ | |
} | |
Plugin.prototype.elementScrolledOff = function(){ | |
} | |
function elementIsOutsideViewport(viewport,offset){ | |
var $viewport = $(viewport); //need to inject test data here | |
return $viewport.scrollTop() > offset.top || $viewport.scrollLeft() > offset.left; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment