Update bottom-visible.md
This commit is contained in:
@ -1,16 +1,9 @@
|
|||||||
### Bottom visible
|
### Bottom visible
|
||||||
|
|
||||||
Returns `true` if bottom of the page is visible. It adds `scrollY` to
|
Use `scrollY`, `scrollHeight` and `clientHeight` to determine if the bottom of the page is visible.
|
||||||
the height of the visible portion of the page (`clientHeight`) and
|
|
||||||
compares it to `pageHeight` to see if bottom of the page is visible.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const bottomVisible = () => {
|
const bottomVisible = _ =>
|
||||||
const scrollY = window.scrollY;
|
document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight || document.documentElement.clientHeight;
|
||||||
const visibleHeight = document.documentElement.clientHeight;
|
// bottomVisible() -> true
|
||||||
const pageHeight = document.documentElement.scrollHeight;
|
|
||||||
const bottomOfPage = visibleHeight + scrollY >= pageHeight;
|
|
||||||
|
|
||||||
return bottomOfPage || pageHeight < visibleHeight;
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user