Skip to content

Instantly share code, notes, and snippets.

@johnkpaul
Created March 15, 2012 02:15
Show Gist options
  • Save johnkpaul/2041247 to your computer and use it in GitHub Desktop.
Save johnkpaul/2041247 to your computer and use it in GitHub Desktop.
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