Created
October 30, 2013 21:36
-
-
Save claviska/7240757 to your computer and use it in GitHub Desktop.
jQuery offscreen plugin
This file contains hidden or 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
/* | |
* jQuery offscreen plugin | |
* | |
* Filters that detect when an element is partially or completely outside | |
* of the viewport. | |
* | |
* Usage: | |
* | |
* $('#element').is(':off-bottom') | |
* | |
* The above example returns true if #element's bottom edge is even 1px past | |
* the bottom part of the viewport. | |
* | |
* Copyright Cory LaViska for A Beautiful Site, LLC. (http://www.abeautifulsite.net/) | |
* | |
* Licensed under the MIT license: http://opensource.org/licenses/MIT | |
* | |
*/ | |
(function($) { | |
$.extend($.expr[':'], { | |
'off-top': function(el) { | |
return $(el).offset().top < $(window).scrollTop(); | |
}, | |
'off-right': function(el) { | |
return $(el).offset().left + $(el).outerWidth() - $(window).scrollLeft() > $(window).width(); | |
}, | |
'off-bottom': function(el) { | |
return $(el).offset().top + $(el).outerHeight() - $(window).scrollTop() > $(window).height(); | |
}, | |
'off-left': function(el) { | |
return $(el).offset().left < $(window).scrollLeft(); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is handy!