Created
April 16, 2022 16:42
-
-
Save Huweicai/1693786c24fb0f35573d3d4d1227060e to your computer and use it in GitHub Desktop.
Flip for GSAP
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
<div class="container final"> | |
<div class="letter F">F</div> | |
<div class="letter l">l</div> | |
<div class="letter i">i</div> | |
<div class="letter p">p</div> | |
<div class="for">for</div> | |
<div class="gsap">GSAP</div> | |
</div> | |
<a href="https://greensock.com/"><img src="https://assets.codepen.io/16327/hero-logo.svg" class="logo" /></a> |
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
gsap.registerPlugin(Flip); | |
let layouts = ["final", "plain", "columns", "grid"], | |
container = document.querySelector(".container"), | |
curLayout = 0; // index of the current layout | |
function nextState() { | |
const state = Flip.getState(".letter, .for, .gsap", {props: "color,backgroundColor", simple: true}); // capture current state | |
container.classList.remove(layouts[curLayout]); // remove old class | |
curLayout = (curLayout + 1) % layouts.length; // increment (loop back to the start if at the end) | |
container.classList.add(layouts[curLayout]); // add the new class | |
Flip.from(state, { // animate from the previous state | |
absolute: true, | |
stagger: 0.07, | |
duration: 0.7, | |
ease: "power2.inOut", | |
spin: curLayout === 0, // only spin when going to the "final" layout | |
simple: true, | |
onEnter: (elements, animation) => gsap.fromTo(elements, {opacity: 0}, {opacity: 1, delay: animation.duration() - 0.1}), | |
onLeave: elements => gsap.to(elements, {opacity: 0}) | |
}); | |
gsap.delayedCall(curLayout === 0 ? 3.5 : 1.5, nextState); | |
} | |
gsap.delayedCall(1, nextState); |
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
<script src="https://assets.codepen.io/16327/gsap-latest-beta.min.js"></script> | |
<script src="https://assets.codepen.io/16327/Flip.min.js"></script> |
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
* { | |
box-sizing: border-box; | |
} | |
body { | |
background: black; | |
padding: 0; | |
margin: 0; | |
font-family: "Signika Negative", sans-serif, Arial; | |
font-weight: 300; | |
height: 100vh; | |
overflow: hidden; | |
} | |
.container { | |
display: flex; | |
height: 100%; | |
width: 100%; | |
justify-content: center; | |
align-items: center; | |
overflow: hidden; | |
} | |
.container.grid, .container.columns { | |
align-content: stretch; | |
align-items: stretch; | |
flex-wrap: wrap; | |
} | |
.letter { | |
text-align: center; | |
color: black; | |
font-size: 10vmax; | |
font-weight: 400; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
padding: 2px 6px; | |
} | |
.container.grid .letter { | |
flex-basis: 50%; | |
} | |
.container.columns .letter { | |
flex-basis: 25%; | |
} | |
.for, .gsap { | |
font-size: 5vmax; | |
color: white; | |
} | |
.for { | |
padding: 2px 1.6vmax; | |
font-weight: 300; | |
display: none; | |
} | |
.gsap { | |
padding: 2px 0; | |
font-weight: 600; | |
display: none; | |
} | |
.container.final .for, .container.final .gsap { | |
display: block; | |
} | |
.F { | |
background: rgba(0, 188, 212, 0.7); | |
} | |
.l { | |
background: rgba(40, 150, 255, 0.7); | |
} | |
.i { | |
background: rgba(153, 80, 220, 0.7); | |
} | |
.p { | |
background: rgba(90, 108, 225, 0.7); | |
} | |
.container.plain .letter { | |
background: transparent; | |
color: white; | |
padding: 0; | |
} | |
.logo { | |
position: fixed; | |
width: 60px; | |
bottom: 20px; | |
right: 30px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment