Files
30-seconds-of-code/snippets/elementBiggerThanViewport.md
2020-10-05 22:08:39 -03:00

575 B

title, tags
title tags
elementBiggerThanViewport beginner

Get elements in html bigger than the viewport width, useful when you're looking for what is causing the horizontal scroll

  • Returns all elements that are bigger than the viewport
const getElementsBiggerThanViewport = () =>
  let docWidth = document.documentElement.offsetWidth;

  [].forEach.call(
    document.querySelectorAll('*'),
    (el) => {
      if (el.offsetWidth > docWidth) console.log('el', el);
    }
  );
  
getElementsBiggerThanViewport(); // <section id="about">...</section>