Last active
October 13, 2018 18:59
-
-
Save dustintheweb/50d248a243cbe34cbab293537d11a65c to your computer and use it in GitHub Desktop.
Elements in Viewport Fn
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
const main = {}; | |
const inViewport = ($el) => { | |
let winTop = main.winScroll; | |
let winBtm = winTop + main.winHeight; | |
let $elTop = $el.offset().top; | |
let $elBtm = $elTop + $el.outerHeight(); | |
return $elBtm > winTop && $elTop < winBtm; | |
} | |
if (inViewport($el) === true) { | |
// stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment