I've been struggling to implement locomotive-scroll and Gsap into a Nuxt project. Something I believe to do with the DOM and SSR. I checked all the docs from scrollproxy Gsap, to Nuxt and locomotive, but I have no more clues.
If you guys have any recommendation, help is more than welcome. Thank you for your time.
Here are the errors
TypeError: Cannot read property 'scroll' of undefined
Uncaught TypeError: _triggers[_i].update is not a function
Uncaught TypeError: Cannot read property 'match' of undefined
Created in plugins/locomotive.js
import Vue from "vue";
import locomotiveScroll from "locomotive-scroll";
Object.defineProperty(Vue.prototype, "locomotiveScroll", {
value: locomotiveScroll
});
Configured in nuxt.config.js
css: [
//smooth scroll
'@/assets/css/scroll.css',
],
plugins: [
{
src: "~/plugins/locomotive.js",
mode: "client"
}
],
Added in app.vue
<script>
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
import LocomotiveScroll from "locomotive-scroll"
</script>
Fired in the mounted hook of app.vue
this.locoScroll = new LocomotiveScroll({
el: document.querySelector('.smooth-scroll'),
smooth: true,
})
this.locoScroll.on('scroll', ScrollTrigger.update)
ScrollTrigger.scrollerProxy('.smooth-scroll', {
scrollTop(value) {
return arguments.length
? this.locoScroll.scrollTo(value, 0, 0)
: this.locoScroll.scroll.instance.scroll.y
},
getBoundingClientRect() {
return { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight }
},
pinType: document.querySelector('.smooth-scroll').style.transform ? 'transform' : 'fixed',
})
ScrollTrigger.addEventListener('refresh', () => this.locoScroll.update())
ScrollTrigger.refresh()