Last active
August 29, 2015 14:02
-
-
Save LukyVj/c924c51bbf21b4f7eaac to your computer and use it in GitHub Desktop.
jQuery :offscreen / :onscreen params
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
// This code snippet is from : http://stackoverflow.com/questions/8897289/how-to-check-if-element-is-off-screen | |
jQuery.expr.filters.onscreen = function(el) { | |
return ( | |
(el.offsetLeft + el.offsetWidth) > 0 | |
|| (el.offsetTop + el.offsetHeight) > 0 | |
|| (el.offsetLeft > window.innerWidth || el.offsetTop < window.innerHeight) | |
); | |
}; | |
jQuery.expr.filters.offscreen = function(el) { | |
return ( | |
(el.offsetLeft + el.offsetWidth) < 0 | |
|| (el.offsetTop + el.offsetHeight) < 0 | |
|| (el.offsetLeft > window.innerWidth || el.offsetTop > window.innerHeight) | |
); | |
}; | |
// returns all elements that are offscreen | |
//$(':offscreen'); | |
// boolean returned if element is offscreen | |
//$('div').is(':offscreen'); | |
// returns all elements that are onscreen | |
//$(':onscreen'); | |
// boolean returned if element is onscreen | |
//$('div').is(':onscreen'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment