Last active
March 21, 2018 16:48
-
-
Save telekineticyeti/7ec7147f8578011e8bda18476b4d34af to your computer and use it in GitHub Desktop.
GSAP multiple element timeline hover in/out effect
This file contains hidden or 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
// Creates the element timeline | |
function bucketAnimation(element) { | |
var tl = new TimelineMax(), | |
bucket = $(element); | |
tl | |
.to(bucket.find('p'), .5, { opacity: 0 }) | |
.to(bucket.find('ul'), 0, { opacity: 1 }) | |
.staggerFrom(bucket.find('li'), .4, { opacity: 0, y: 100, ease: Back.easeOut }, .15); | |
return tl; | |
} | |
// Plays the element timeline | |
function bucketIn() { | |
if (!this.animation) { | |
this.animation = bucketAnimation(this); | |
} else { | |
this.animation.play().timeScale(1); | |
} | |
} | |
// Reverses the element timeline | |
function bucketOut() { | |
this.animation.reverse().timeScale(4); | |
} | |
// Trigger the timeline | |
$('.cta_buckets .bucket').hover(bucketIn, bucketOut); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment