我正在使用nuxt-locomotive-scroll
并gsap
收到以下错误。
_this.elementAnimation 不是函数
如何正确调用elementAnimation()
包含在initScrolltrigger()
export default {
mounted() {
this.initScrolltrigger()
// How can I call this.elementAnimation(element)?
this.$nextTick(() => {
const elements = document.querySelectorAll('[data-scroll-trigger]')
elements.forEach((element) => this.elementAnimation(element))
})
},
methods: {
initScrolltrigger() {
const locomotive = this.$refs.scroller.locomotive
locomotive.on('scroll', ScrollTrigger.update)
ScrollTrigger.scrollerProxy(locomotive.el, {
scrollTop(value) {
return arguments.length
? locomotive.scrollTo(value, 0, 0)
: locomotive.scroll.instance.scroll.y
},
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight,
}
},
elementAnimation(element) {
gsap.from(element, {
scrollTrigger: {
trigger: element,
scroller: this.$refs.scroller.locomotive.el,
scrub: true,
markers: true,
start: 'top top',
end: 'bottom center',
},
scale: 0,
ease: 'none',
})
},
})
},
},
}