Last active
October 12, 2024 16:17
-
-
Save liborvanek/e5d2af39cdbbbbb7838c7a03bdc3f59a to your computer and use it in GitHub Desktop.
Page transition mixin for Nuxt.js with GreenSock GSAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TimelineMax, TweenMax, Power2, Back } from 'gsap' | |
let curtainsOpenTimeline = () => { | |
return new TimelineMax() | |
.set('.curtains', { transformOrigin: '0%' }) | |
.fromTo('.curtains', 0.6, { scaleX: 0 }, { scaleX: 1, ease: Power2.easeInOut }) | |
.fromTo('.curtains-logo', 0.3, { x: '-100%', autoAlpha: 0 }, { x: '-50%', autoAlpha: 1, ease: Power2.easeInOut }, '-=0.45') | |
} | |
let curtainsCloseTimeline = () => { | |
return new TimelineMax() | |
.set('.curtains', { transformOrigin: '100%' }) | |
.to('.curtains', 0.6, { scaleX: 0, ease: Power2.easeInOut }) | |
.fromTo('.curtains-logo', 0.3, { x: '-50%', autoAlpha: 1 }, { x: '0%', autoAlpha: 0, ease: Power2.easeInOut }, '-=0.5') | |
} | |
let caseStudyReveal = () => { | |
return new TimelineMax() | |
.staggerTo('.st', 0.3, { autoAlpha: 1, y: '0%', ease: Back.easeOut.config(3.7) }, 0.05, '-=0.2') | |
.fromTo('.project-header-year', 0.3, { autoAlpha: 0, y: '20%' }, { autoAlpha: 1, y: '0%' }, '-=0.6') | |
} | |
let projectsHeroReveal = () => { | |
return TweenMax.staggerTo('.st', 0.3, { autoAlpha: 1, y: '0%', ease: Back.easeOut.config(3.7) }, 0.05) | |
} | |
let hideStaggers = () => { | |
return TweenMax | |
.set('.st', { autoAlpha: 0, y: '-18px' }) | |
} | |
const createTransitionMixin = (leaveTweens = [], enterTweens = []) => { | |
return { | |
transition: { | |
css: false, | |
mode: 'out-in', | |
leave (el, done) { | |
if (!this.$store.state.menuIsAnimating) { | |
let leaveTimeline = new TimelineMax() | |
leaveTweens.forEach(tween => { | |
leaveTimeline.add(tween()) | |
}) | |
leaveTimeline.eventCallback('onComplete', done) | |
} else { | |
done() | |
} | |
}, | |
enter (el, done) { | |
if (!this.$store.state.menuIsAnimating) { | |
let enterTimeline = new TimelineMax() | |
enterTweens.forEach(tween => { | |
enterTimeline.add(tween()) | |
}) | |
enterTimeline.eventCallback('onComplete', done) | |
} else { | |
done() | |
} | |
} | |
} | |
} | |
} | |
export let CurtainTransitionBasic = createTransitionMixin( | |
[ curtainsOpenTimeline ], | |
[ curtainsCloseTimeline ] | |
) | |
export let CurtainTransitionCaseStudy = createTransitionMixin( | |
[ curtainsOpenTimeline ], | |
[ curtainsCloseTimeline, hideStaggers, caseStudyReveal ] | |
) | |
export let CurtainTransitionProjectList = createTransitionMixin( | |
[ curtainsOpenTimeline ], | |
[ curtainsCloseTimeline, hideStaggers, projectsHeroReveal ] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then in the page.vue: