dixonandmoe / rellax

Lightweight, vanilla javascript parallax library
https://dixonandmoe.com/rellax/
MIT License
7.04k stars 880 forks source link

Rellax + Nuxt: wokrs at page load, not at page change/transition #209

Closed valeriosillari closed 4 years ago

valeriosillari commented 4 years ago

Not sure if off-topic, but I'm not sure where to ask for support, so I try here :)

Rellax seems not working on a Nuxt application when I pass from one page to another.

I mean: my Nuxt application is made by 2 pages, call them A and B. I've added Rellax as a global plugin. I put a small Rellax animation on both pages A and B.

If I load directly page A, all good. If I load directly page B, all good.

But if I call page A and then page B (clicking on link from page A to B), Rellax is not working anymore (and no console error or warnings.)

I guess it's related on how Nuxt handles page transition/changes and probably destroy or not re-init Rellax. I've used different times Nuxt and loaded plugins as global ones (on client side), this is the first time I experience a similar issue.

Anyone could support me?

egrechko commented 4 years ago

Where are you initializing rellax in vue? If you initialize rellax on the mounted hook you should be all good.

export default {
...
  mounted() {
    // eslint-disable-next-line
    const rellax = new Rellax(this.$refs.parallaxImg)
  }
}
...

Hope this helps.

valeriosillari commented 4 years ago

Thanks for the tip, it works :)