18
README.md
18
README.md
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
|
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
|
||||||
* [Average of array of numbers](#average-of-array-of-numbers)
|
* [Average of array of numbers](#average-of-array-of-numbers)
|
||||||
|
* [Bottom visible](#bottom-visible)
|
||||||
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
|
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
|
||||||
* [Capitalize first letter](#capitalize-first-letter)
|
* [Capitalize first letter](#capitalize-first-letter)
|
||||||
* [Chain asynchronous functions](#chain-asynchronous-functions)
|
* [Chain asynchronous functions](#chain-asynchronous-functions)
|
||||||
@ -92,6 +93,23 @@ const average = arr =>
|
|||||||
// average([1,2,3]) -> 2
|
// average([1,2,3]) -> 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Bottom visible
|
||||||
|
|
||||||
|
Returns `true` if bottom of the page is visible. It adds `scrollY` to
|
||||||
|
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
|
||||||
|
const bottomVisible = () => {
|
||||||
|
const scrollY = window.scrollY;
|
||||||
|
const visibleHeight = document.documentElement.clientHeight;
|
||||||
|
const pageHeight = document.documentElement.scrollHeight;
|
||||||
|
const bottomOfPage = visibleHeight + scrollY >= pageHeight;
|
||||||
|
|
||||||
|
return bottomOfPage || pageHeight < visibleHeight;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Capitalize first letter of every word
|
### Capitalize first letter of every word
|
||||||
|
|
||||||
Use `replace()` to match the first character of each word and `toUpperCase()` to capitalize it.
|
Use `replace()` to match the first character of each word and `toUpperCase()` to capitalize it.
|
||||||
|
|||||||
9
snippets/bottom-visible.md
Normal file
9
snippets/bottom-visible.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
### Bottom visible
|
||||||
|
|
||||||
|
Use `scrollY`, `scrollHeight` and `clientHeight` to determine if the bottom of the page is visible.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bottomVisible = _ =>
|
||||||
|
document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight || document.documentElement.clientHeight;
|
||||||
|
// bottomVisible() -> true
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user