Merge pull request #623 from Chalarangelo/smoothScrolling
[FEATURE] Smooth scrolling
This commit is contained in:
18
snippets/smoothScroll.md
Normal file
18
snippets/smoothScroll.md
Normal file
@ -0,0 +1,18 @@
|
||||
### smoothScroll
|
||||
|
||||
Smoothly scrolls the element on which it's called into the visible area of the browser window.
|
||||
|
||||
Use `.scrollIntoView` method to scroll the element.
|
||||
Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly.
|
||||
|
||||
```js
|
||||
const smoothScroll = element =>
|
||||
document.querySelector(element).scrollIntoView({
|
||||
behavior: 'smooth'
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar
|
||||
smoothScroll('.fooBar'); // scrolls smoothly to the first element with a class of fooBar
|
||||
```
|
||||
@ -229,6 +229,7 @@ shuffle:array,random
|
||||
similarity:array,math
|
||||
size:object,array,string
|
||||
sleep:function,promise
|
||||
smoothScroll:browser,css
|
||||
sortCharactersInString:string
|
||||
sortedIndex:array,math
|
||||
sortedIndexBy:array,math,function
|
||||
|
||||
Reference in New Issue
Block a user