Skip to content

this.$gsap unknown in document.addEventListener #40

Answered by ivodolenc
pit07 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, the module works fine, here is an example for mouse animation.

When using events in vue/nuxt, the best practice is to add them in the mounted hook and remove them in the destroy hook to avoid possible issues later in the dev.

Also keep in mind that you will need some kind of raf or gsap.ticker for better performance.

<template>
  <div>
    <div ref="cursor">Cursor</div>
  </div>
</template>

<script>
  export default {
    mounted() {
      this.mouseMounted()
    },

    beforeDestroy() {
      this.mouseDestroyed()
    },

    methods: {
      cursorAnimation(e) {
        this.$gsap.to(this.$refs.cursor, {
          x: e.pageX,
          y: e.pageY,
        })
      },

      mouseM…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ivodolenc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants