vue on page link code example
Example 1: vue on page link or anchor
import { scroll } from 'quasar'
const { getScrollTarget, setScrollPosition } = scroll
scrollToElement (id) {
if (id && id !== '') {
let el = document.querySelector(id)
if (el) {
const target = getScrollTarget(el)
const offset = el.offsetTop
const duration = 1000
setScrollPosition(target, offset, duration)
}
}
},
Example 2: vue on page link or anchor
scrollToElement (id) {
const el = document.querySelector(id)
el && el.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" })
}
Example 3: vue on page link or anchor
methods: {
scrollMeTo(refName) {
var element = this.$refs[refName];
var top = element.offsetTop;
window.scrollTo(0, top);
}
}