Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arvin iuunhao
Added: Jun 18, 2018 8:15 AM
Views: 8
Tags: js
  1. const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
  2.   const { top, left, bottom, right } = el.getBoundingClientRect();
  3.   return partiallyVisible
  4.     ? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
  5.     ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
  6.     : top >= 0 && left >= 0 && bottom < = innerHeight && right <= innerWidth;
  7. };