2021-10-20 10:24:04 +08:00
|
|
|
function timeout (t) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
setTimeout(resolve, t)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export default async function scrollBehavior (to) {
|
2021-10-18 18:52:29 +08:00
|
|
|
if (to.hash) {
|
2020-08-13 11:47:56 +08:00
|
|
|
// scroll to anchor by returning the selector
|
2021-10-20 10:24:04 +08:00
|
|
|
await timeout(0)
|
2021-10-18 18:52:29 +08:00
|
|
|
return {
|
|
|
|
selector: decodeURIComponent(to.hash),
|
|
|
|
offset: {
|
2021-10-21 00:43:25 +08:00
|
|
|
y: 120
|
2021-10-18 18:52:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
2020-08-13 11:47:56 +08:00
|
|
|
}
|
|
|
|
}
|