Prepare repository for merge
This commit is contained in:
25
javascript/snippets/get-elements-bigger-than-viewport.md
Normal file
25
javascript/snippets/get-elements-bigger-than-viewport.md
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
title: Get elements bigger than viewport
|
||||
type: snippet
|
||||
tags: [browser]
|
||||
cover: case-study
|
||||
dateModified: 2020-10-22T20:23:47+03:00
|
||||
---
|
||||
|
||||
Returns an array of HTML elements whose width is larger than that of the viewport's.
|
||||
|
||||
- Use `HTMLElement.offsetWidth` to get the width of the `Document`.
|
||||
- Use `Array.prototype.filter()` on the result of `Document.querySelectorAll()` to check the width of all elements in the document.
|
||||
|
||||
```js
|
||||
const getElementsBiggerThanViewport = () => {
|
||||
const docWidth = document.documentElement.offsetWidth;
|
||||
return [...document.querySelectorAll('*')].filter(
|
||||
el => el.offsetWidth > docWidth
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
getElementsBiggerThanViewport(); // <div id="ultra-wide-item" />
|
||||
```
|
||||
Reference in New Issue
Block a user