Jump to content
Search Community

scrollSmoother on Nuxt

kaique test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hello guys, I'm trying to use scrollSmoother on a Nuxt app and it works fine on the first mount, however if I change route and get back it doesn't work anymore, is there any kind of .kill or .update that I have to do? Also using the nuxt-gsap-module :)


Cheers,
Kaique
 

<template lang="pug">
  main#smooth-wrapper(v-if="!isLoading")
    NuxtLink(to="/")
      span.hide go index

    ul
      li(v-for="image in $data.imagesToPreload")
        img.hide(:src=`image`)
</template>

<script>
  export default {
    mounted() {
      const images = this.imagesToPreload.map(imageSrc => {
        return new Promise((resolve, reject) => {
          const img = new Image()
          img.src = imageSrc
          img.onload = resolve
          img.onerror = reject
        })
      })

      Promise.all(images).then(() => {
        this.isLoading = false
      }),

      this.$ScrollSmoother.create({
        smooth: 1.6
      })
    },

    data() {
      return {
        isLoading: true,
        imagesToPreload: [
          "https://placeimg.com/1280/800/any"
        ]
      }
    }
  }
</script>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...