Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Last active October 13, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustintheweb/50d248a243cbe34cbab293537d11a65c to your computer and use it in GitHub Desktop.
Save dustintheweb/50d248a243cbe34cbab293537d11a65c to your computer and use it in GitHub Desktop.
Elements in Viewport Fn
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