git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: b8398e992d3576abf221688bc4cd3c9a976b8834

Files: b8398e992d3576abf221688bc4cd3c9a976b8834 / lib / anchor-hook.js

585 bytesRaw
1var watch = require('mutant/watch')
2
3module.exports = AnchorHook
4
5function AnchorHook (name, current, cb) {
6 return function (element) {
7 return watch(current, (current) => {
8 if (current === name) {
9 window.requestAnimationFrame(() => {
10 element.scrollIntoView()
11
12 // HACK: due to a browser bug, sometimes the body gets affected!?
13 // Why not just hack it!!!
14 if (document.body.scrollTop > 0) {
15 document.body.scrollTop = 0
16 }
17
18 if (typeof cb === 'function') cb(element)
19 })
20 }
21 })
22 }
23}
24

Built with git-ssb-web