From 1dea5e43e2ddc74a9cefd8f4c64cb30315e61691 Mon Sep 17 00:00:00 2001 From: Alcides A Date: Mon, 5 Oct 2020 22:08:39 -0300 Subject: [PATCH] add elementbiggerthanviewport --- snippets/elementBiggerThanViewport.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 snippets/elementBiggerThanViewport.md diff --git a/snippets/elementBiggerThanViewport.md b/snippets/elementBiggerThanViewport.md new file mode 100644 index 000000000..511573da7 --- /dev/null +++ b/snippets/elementBiggerThanViewport.md @@ -0,0 +1,27 @@ +--- +title: elementBiggerThanViewport +tags: 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 + +```js +const getElementsBiggerThanViewport = () => + let docWidth = document.documentElement.offsetWidth; + + [].forEach.call( + document.querySelectorAll('*'), + (el) => { + if (el.offsetWidth > docWidth) console.log('el', el); + } + ); + +``` + +```js +getElementsBiggerThanViewport(); //
...
+``` + +