A Pen by Mark Thomes on CodePen.
Created
August 27, 2020 19:03
-
-
Save mthomes/c19d42fb6e1cb6b3f6ff1cb4316c4444 to your computer and use it in GitHub Desktop.
bGpWYRB
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
<button type="button" class="cta"> | |
<span class="slide"> | |
<span class="slide-part"> | |
<span class="label">Add to cart</span> | |
</span> | |
<span class="slide-part"> | |
<span class="label">1 in cart</span> | |
<span class="icon"> | |
<svg viewBox="0 0 32 27" height="27"> | |
<rect x="4" y="4" width="24" height="19" fill="transparent" stroke="white" stroke-width="3" /> | |
</svg> | |
</span> | |
</span> | |
</span> | |
</button> |
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
const cta = document.querySelector(".cta"); | |
cta.addEventListener("click", () => { | |
cta.classList.toggle("full"); | |
}); |
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
body { | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
min-height: 100vh; | |
font-family: "Montserrat", sans-serif; | |
font-weight: bold; | |
background-color: whitesmoke; | |
} | |
* { | |
font-family: "Montserrat", sans-serif; | |
font-weight: bold; | |
} | |
.cta { | |
width: 242px; | |
appearance: none; | |
background-color: red; | |
color: white; | |
border: none; | |
font-size: 21px; | |
height: 54px; | |
align-items: center; | |
justify-content: center; | |
display: flex; | |
border-radius: 27px; | |
position: relative; | |
overflow: hidden; | |
&:focus { | |
outline: none; | |
} | |
} | |
.cta span { | |
white-space: nowrap; | |
} | |
.icon { | |
margin-left: 6px; | |
position: relative; | |
transform-origin: 0 100%; | |
&::after { | |
position: absolute; | |
top: 0; | |
right: 0; | |
} | |
} | |
.slide { | |
transform: translateY(0); | |
transition: transform 250ms cubic-bezier(0.83, 0, 0.17, 1); | |
} | |
.slide, | |
.slide-part { | |
position: absolute; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
} | |
.slide-part { | |
height: 54px; | |
} | |
.slide-part:nth-child(2) { | |
top: 54px; | |
} | |
.full { | |
.slide { | |
transform: translateY(-100%); | |
} | |
.icon { | |
animation: secondaryBounce 400ms linear forwards 150ms; | |
} | |
} | |
@keyframes secondaryBounce { | |
0% { | |
animation-timing-function: cubic-bezier(0.25, 1, 0.5, 1); | |
transform: rotate(0); | |
} | |
50% { | |
animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); | |
transform: rotate(-6deg); | |
} | |
100% { | |
transform: rotate(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment