Merge pull request #623 from Chalarangelo/smoothScrolling

[FEATURE] Smooth scrolling
This commit is contained in:
Angelos Chalaris
2018-03-03 14:42:59 +02:00
committed by GitHub
2 changed files with 19 additions and 0 deletions

18
snippets/smoothScroll.md Normal file
View 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
```

View File

@ -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