|
3 | 3 |
|
4 | 4 | var article = document.querySelector('article.doc')
|
5 | 5 | var toolbar = document.querySelector('.toolbar')
|
| 6 | + var supportsScrollToOptions = 'scrollTo' in document.documentElement |
6 | 7 |
|
7 | 8 | function decodeFragment (hash) {
|
8 | 9 | return hash && (~hash.indexOf('%') ? decodeURIComponent(hash) : hash).slice(1)
|
|
18 | 19 | window.location.hash = '#' + this.id
|
19 | 20 | e.preventDefault()
|
20 | 21 | }
|
21 |
| - window.scrollTo(0, computePosition(this, 0) - toolbar.getBoundingClientRect().bottom) |
| 22 | + var y = computePosition(this, 0) - toolbar.getBoundingClientRect().bottom |
| 23 | + var instant = e === false && supportsScrollToOptions |
| 24 | + instant ? window.scrollTo({ left: 0, top: y, behavior: 'instant' }) : window.scrollTo(0, y) |
22 | 25 | }
|
23 | 26 |
|
24 | 27 | window.addEventListener('load', function jumpOnLoad (e) {
|
25 | 28 | var fragment, target
|
26 | 29 | if ((fragment = decodeFragment(window.location.hash)) && (target = document.getElementById(fragment))) {
|
27 |
| - document.documentElement.style.scrollBehavior = 'auto' |
28 |
| - jumpToAnchor.call(target) |
29 |
| - setTimeout(jumpToAnchor.bind(target), 0) |
30 |
| - setTimeout(function () { |
31 |
| - document.documentElement.style.scrollBehavior = '' |
32 |
| - }) |
| 30 | + jumpToAnchor.call(target, false) |
| 31 | + setTimeout(jumpToAnchor.bind(target, false), 250) |
33 | 32 | }
|
34 | 33 | window.removeEventListener('load', jumpOnLoad)
|
35 | 34 | })
|
|
0 commit comments