24 lines
375 B
JavaScript
24 lines
375 B
JavaScript
function timeout (t) {
|
|
return new Promise(resolve => {
|
|
setTimeout(resolve, t)
|
|
})
|
|
}
|
|
|
|
export default async function scrollBehavior (to) {
|
|
if (to.hash) {
|
|
// scroll to anchor by returning the selector
|
|
await timeout(0)
|
|
return {
|
|
selector: decodeURIComponent(to.hash),
|
|
offset: {
|
|
y: 32
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
x: 0,
|
|
y: 0
|
|
}
|
|
}
|