Created
May 12, 2011 07:30
-
-
Save Takazudo/968093 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
/*! | |
* $.fn.isInWindow | |
* | |
* version 0.0.1 (2010/11/17) | |
* author: Takeshi Takatsudo (takazudo[at]gmail.com) | |
* license: MIT | |
* depends: jQuery 1.4.4 | |
*/ | |
(function($, undefined){ // start encapsulation | |
var $win = $(window); | |
$.fn.isAboveTheWindow = function(opitons){ | |
var $el = this; | |
if($el.size()>1){ | |
$.error('2 or more elements were thrown.'); | |
return false; | |
} | |
var o = $.extend({ | |
threshold: 0 | |
},opitons); | |
return ($win.scrollTop() >= $el.offset().top + o.threshold + $el.innerHeight()); | |
}; | |
$.fn.isBelowTheWindow = function(options){ | |
var $el = this; | |
if($el.size()>1){ | |
$.error('2 or more elements were thrown.'); | |
return false; | |
} | |
var o = $.extend({ | |
threshold: 0 | |
},options); | |
return $win.height() + $win.scrollTop() <= $el.offset().top - o.threshold; | |
}; | |
$.fn.isInWindow = function(){ | |
var $el = this; | |
return !$el.isAboveTheWindow() && !$el.isBelowTheWindow(); | |
}; | |
})(jQuery); // end encapsulation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment