Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active August 11, 2017 06:42
Show Gist options
  • Save andreasvirkus/d9e09ee119a00b4e1b5957c6e5d7939d to your computer and use it in GitHub Desktop.
Save andreasvirkus/d9e09ee119a00b4e1b5957c6e5d7939d to your computer and use it in GitHub Desktop.
/**
* VueRouter's scrollBehavior for scrolling to anchor links
*
* TODO: Swap TweenLite maybe for my custom jump.s snippet or jump.js lib (10kB vs 0.4kB vs 1.3kB)
* https://github.com/callmecavs/jump.js
*/
export default new Router({
mode: 'history',
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
TweenLite.to(window, 1, {scrollTo: to.hash, offsetY: 200});
// return {
// selector: to.hash,
// offset: { x: 0, y: 200 },
// };
} else {
console.log('not hash');
return { x: 0, y: 0 };
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment