//Import GreenStock Animation Platform
import gsap from "gsap"
import ScrollTrigger from 'gsap/ScrollTrigger'
gsap.registerPlugin(ScrollTrigger)
// Mounted Lifecycle Hooks
async mounted() {
// Setup the strapline tween.
this.tween = gsap.from(this.$refs.strapline, {
scale: 0.5,
yPercent: 40,
repeat: 0,
duration: 2,
ease: "linear",
}).totalProgress(0.5);
// Run the animation for the strapline
this.scrollAnimationStrapline();
},
data() {
return {
currentScroll: 0,
isScrollingDown: true,
tween: null,
}
},
// Methods
methods: {
// Scroll animation for the strapline.
scrollAnimationStrapline() {
gsap.to(this.$refs.strapline, {
xPercent: 0,
scrollTrigger: {
trigger: this.$refs.trigger,
start: "top center",
// scroller: '.content-scroll',
scrub: true,
markers: true,
}
});
},
// Handle the scrolling event
handleScroll(event: any) {
console.log('Triggered scrolling event');
console.log(event.detail.scrollTop, this.currentScroll);
// Set the current scroll position.
if (event.detail.scrollTop > this.currentScroll) {
this.isScrollingDown = true;
} else {
this.isScrollingDown = false;
}
// Set the time scale of the strapline tween
gsap.to(this.tween, {
timeScale: this.isScrollingDown ? -1 : 1
});
// Set the current scroll position.
this.currentScroll = event.detail.scrollTop;
}
}