New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ScrollTrigger in templates with v-gsap #28
Comments
Hi, yeah, it's possible. Just activate // nuxt.config.js
export default {
buildModules: ['nuxt-gsap-module'],
gsap: {
extraPlugins: {
scrollTrigger: true
}
}
} Here is a simple example: <template>
<div>
<section style="height: 150vh"></section>
<h1
class="title"
v-gsap.to="{
scrollTrigger: {
trigger: '.title',
start: 'center bottom',
end: 'center top',
scrub: true,
markers: true
},
x: 500
}"
>
Nuxt GSAP Module
</h1>
<section style="height: 150vh"></section>
</div>
</template> |
But keep in mind if you use Maybe it's better to use it inside Docs: Simple example: <template>
<div>
<nuxt-link to="/about">About</nuxt-link>
<section style="height: 150vh"></section>
<h1 class="title">Nuxt GSAP Module</h1>
<section style="height: 150vh"></section>
</div>
</template>
<script>
export default {
methods: {
customScrollTrigger() {
this.$gsap.to('.title', {
scrollTrigger: {
id: 'title01', // Add unique Id
trigger: '.title',
start: 'center bottom',
end: 'center top',
scrub: true,
markers: true
},
x: 500
})
}
},
mounted() {
this.customScrollTrigger()
},
beforeDestroy() {
// Returns the ScrollTrigger with unique Id
// and kills it before route change
this.$ScrollTrigger.getById('title01').kill()
}
}
</script> |
Hi! Thanks for the quick response, I'll gladly give this module a star! I enjoy using GSAP but I'm learning Nuxt and how to implement it correctly. Sorry if these questions are a bit pity hahaha. I have created a Sandbox (My first one, I hope to link it correctly) to see this demo the animation works except the scrub. Any idea why? |
Read docs and try out simple step-by-step examples. Also, try to simplify the code. Create a component, animate it and import it where needed. Here is a working example: <template>
<div>
<NuxtLink to="/">Page 1</NuxtLink>
<NuxtLink to="/about">Page 2</NuxtLink>
<section style="min-height: 100vh; background: gray"></section>
<h1 id="js-trigger">My list with v-gsap</h1>
<ul>
<li v-for="item in myList" :key="item" class="itemsA">
{{ item }}
</li>
</ul>
<section style="min-height: 100vh; background: gray"></section>
<h1 id="js-trigger2">My list with gsap</h1>
<ul>
<li v-for="item in myList" :key="item" class="itemsB">
{{ item }}
</li>
</ul>
<section style="min-height: 100vh; background: gray"></section>
</div>
</template>
<script>
export default {
data() {
return {
myList: ['First', 'Second', 'Third']
}
},
mounted() {
this.firstTween()
this.secondTween()
},
methods: {
firstTween() {
this.$gsap.to('.itemsA', {
scrollTrigger: {
id: 'firstTween',
trigger: '#js-trigger',
start: 'center 75%',
end: 'center 75%',
scrub: 1,
markers: true
},
x: 300,
opacity: 0,
stagger: 0.1
})
},
secondTween() {
this.$gsap.fromTo(
'.itemsB',
{
x: 300,
opacity: 0,
stagger: 0.1
},
{
scrollTrigger: {
id: 'secondTween',
trigger: '#js-trigger2',
start: 'center 75%',
end: 'center 75%',
scrub: 1,
markers: true
},
x: 0,
opacity: 1,
stagger: 0.1
}
)
}
},
beforeDestroy() {
// Returns the ScrollTrigger with unique Id
// and kills it before route change
this.$ScrollTrigger.getById('firstTween').kill()
this.$ScrollTrigger.getById('secondTween').kill()
}
}
</script> |
Hi, I wonder if it's possible to add scrollTrigger inside the v-gsap and how. I have tried without any success and can't find it on the docs.
Use in templates
The text was updated successfully, but these errors were encountered: