1

我正在使用nuxt-locomotive-scrollgsap收到以下错误。

_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',
          })
        },
      })
    },
  },
}
4

1 回答 1

0

您的elementAnimation函数实际上嵌套在initScrolltrigger(and ScrollTrigger.scrollerProxy) 中,不确定是否需要。

如果您正在寻找更新,您可能应该在这里以不同的方式观看更改。

于 2021-09-22T08:01:36.657 回答