Ocelot-Social/webapp/mixins/scrollToAnchor.js
roschaefer 9da40c4895 fix: avoid many scrollTo calls for n components
Thank you @vbelolapotkov for pointing out the flaws here:
https://github.com/Human-Connection/Human-Connection/pull/1756#discussion_r329361572

So here is my attempt to fix it:
* Install `vue-scrollto` which relies on `requestAnimationFrame`
  - apparently this is better on Safari and IE? 🤔
  - Mocking out entire modules is easier in jest:
    https://jestjs.io/docs/en/bypassing-module-mocks
* Require `checkAnchor` to be implemented on the component
2019-10-01 11:55:18 +02:00

21 lines
431 B
JavaScript

import { scrollTo } from 'vue-scrollto'
export default {
watch: {
$route(to, from) {
const anchor = to && to.hash
if (!this.checkAnchor(anchor)) return
setTimeout(() => {
scrollTo(anchor, 1000)
}, 250)
},
},
mounted() {
const anchor = this.$route && this.$route.hash
if (!this.checkAnchor(anchor)) return
setTimeout(() => {
scrollTo(anchor, 1000)
}, 250)
},
}