Created
January 27, 2014 10:19
-
Star
(189)
You must be signed in to star a gist -
Fork
(34)
You must be signed in to fork a gist
-
-
Save jjmu15/8646226 to your computer and use it in GitHub Desktop.
Revisions
-
jjmu15 revised this gist
Jan 27, 2014 . No changes.There are no files selected for viewing
-
jjmu15 created this gist
Jan 27, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ // Determine if an element is in the visible viewport function isInViewport(element) { var rect = element.getBoundingClientRect(); var html = document.documentElement; return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || html.clientHeight) && rect.right <= (window.innerWidth || html.clientWidth) ); } The above function could be used by adding a “scroll” event listener to the window and then calling isInViewport().