* {
box-sizing: border-box;
}
body {
display: grid;
grid-template-rows: 300px 1fr;
justify-items: stretch;
align-items: center;
overflow: hidden; /* otherwise, if the scrollbar disappears as a result of the tween, the viewport actually gets resized, meaning the measurements are different! */
}
header {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.boxes {
display: flex;
align-items: center;
justify-content: space-around;
}
.target {
position: relative;
background: var(--color-ui-gradient);
width: 250px;
height: 120px;
text-align: center;
border-radius: 10px;
color: var(--color-just-black);
}
.container {
width: 40%;
border-radius: 10px;
border: 2px dashed var(--color-surface-white);
text-align: center;
padding: 15px;
pointer-events: none;
display: flex;
flex-direction: column;
align-items: center;
flex-wrap: wrap;
}
.child1, .child2 {
background: var(--gradient-summer-fair);
height: 120px;
width: 250px;
text-align: center;
margin: 15px 0;
line-height: 100%;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
color: var(--color-just-black);
}
.child1 {
background: transparent;
border: 2px dashed var(--color-surface-white);
}
h1 {
font-weight: 400;
}
.button {
padding: 10px 20px;
margin-bottom: 10px;
}
.logo {
position: absolute;
width: 60px;
bottom: 20px;
right: 30px;
}
.target:after {
content: "target";
position: absolute;
bottom: 100%;
padding-bottom: 0.5rem;
left: 5px;
color: #888;
font-size: 0.75em;
}
gsap.registerPlugin(Flip);
gsap.to(".container", { rotation: 25});
gsap.to(".target", {scale: 1.2, rotation: -18, x: 60, y: 60});
document.querySelector("button").addEventListener("click", () => {
Flip.fit(".container", ".target", {
fitChild: ".child1",
scale: true,
duration: 2,
ease: "power1.inOut"
});
});
View Compiled