Performance measuring, scroll to top, array flattening

This commit is contained in:
Angelos Chalaris
2017-12-07 12:00:34 +02:00
parent 2e68f8ae86
commit 71c915cee6
4 changed files with 76 additions and 0 deletions

14
snippets/scroll-to-top.md Normal file
View File

@ -0,0 +1,14 @@
### Scroll to top
Get distance from top using `document.documentElement.scrollTop` or `document.body.scrollTop`.
Scroll by a fraction of the distance from top. Use `window.requestFrame()` to animate the scrolling.
```js
var scrollToTop = _ => {
var c = document.documentElement.scrollTop || document.body.scrollTop;
if(c > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, c - c/8);
}
}
```