Update formatting
This commit is contained in:
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:23:47+03:00
|
|||||||
|
|
||||||
Checks if the element specified is visible in the viewport.
|
Checks if the element specified is visible in the viewport.
|
||||||
|
|
||||||
- Use `Element.getBoundingClientRect()` and the `Window.inner(Width|Height)` values to determine if a given element is visible in the viewport.
|
- Use `Element.getBoundingClientRect()`, `Window.innerWidth` and `Window.innerHeight` to determine if a given element is visible in the viewport.
|
||||||
- Omit the second argument to determine if the element is entirely visible, or specify `true` to determine if it is partially visible.
|
- Omit the second argument to determine if the element is entirely visible, or specify `true` to determine if it is partially visible.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:23:47+03:00
|
|||||||
|
|
||||||
Returns an array of HTML elements whose width is larger than that of the viewport's.
|
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 `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.
|
- Use `Array.prototype.filter()` on the result of `Document.querySelectorAll()` to check the width of all elements in the document.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -8,7 +8,7 @@ lastUpdated: 2020-10-19T22:49:51+03:00
|
|||||||
Returns the scroll position of the current page.
|
Returns the scroll position of the current page.
|
||||||
|
|
||||||
- Use `Window.pageXOffset` and `Window.pageYOffset` if they are defined, otherwise `Element.scrollLeft` and `Element.scrollTop`.
|
- Use `Window.pageXOffset` and `Window.pageYOffset` if they are defined, otherwise `Element.scrollLeft` and `Element.scrollTop`.
|
||||||
- Omit the single argument, `el`, to use a default value of `window`.
|
- Omit the single argument, `el`, to use the global `Window` object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const getScrollPosition = (el = window) => ({
|
const getScrollPosition = (el = window) => ({
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-20T23:02:01+03:00
|
|||||||
|
|
||||||
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.
|
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.
|
||||||
|
|
||||||
- Use `Array.prototype.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`.
|
- Use `Array.prototype.includes()` on the `typeof` values of both `Window` and `Document` (globals usually only available in a browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`.
|
||||||
- `typeof` allows globals to be checked for existence without throwing a `ReferenceError`.
|
- `typeof` allows globals to be checked for existence without throwing a `ReferenceError`.
|
||||||
- If both of them are not `undefined`, then the current environment is assumed to be a browser.
|
- If both of them are not `undefined`, then the current environment is assumed to be a browser.
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ lastUpdated: 2020-12-31T13:13:47+02:00
|
|||||||
Checks if `localStorage` is enabled.
|
Checks if `localStorage` is enabled.
|
||||||
|
|
||||||
- Use a `try...catch` block to return `true` if all operations complete successfully, `false` otherwise.
|
- Use a `try...catch` block to return `true` if all operations complete successfully, `false` otherwise.
|
||||||
- Use `Storage.setItem()` and `Storage.removeItem()` to test storing and deleting a value in `window.localStorage`.
|
- Use `Storage.setItem()` and `Storage.removeItem()` to test storing and deleting a value in `Window.localStorage`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isLocalStorageEnabled = () => {
|
const isLocalStorageEnabled = () => {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ lastUpdated: 2020-12-31T13:13:47+02:00
|
|||||||
Checks if `sessionStorage` is enabled.
|
Checks if `sessionStorage` is enabled.
|
||||||
|
|
||||||
- Use a `try...catch` block to return `true` if all operations complete successfully, `false` otherwise.
|
- Use a `try...catch` block to return `true` if all operations complete successfully, `false` otherwise.
|
||||||
- Use `Storage.setItem()` and `Storage.removeItem()` to test storing and deleting a value in `window.sessionStorage`.
|
- Use `Storage.setItem()` and `Storage.removeItem()` to test storing and deleting a value in `Window.sessionStorage`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isSessionStorageEnabled = () => {
|
const isSessionStorageEnabled = () => {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ lastUpdated: 2020-10-22T20:24:30+03:00
|
|||||||
|
|
||||||
Checks if touch events are supported.
|
Checks if touch events are supported.
|
||||||
|
|
||||||
- Check if `'ontouchstart'` exists in `window`.
|
- Check if `'ontouchstart'` exists in the `Window`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const supportsTouchEvents = () =>
|
const supportsTouchEvents = () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user