Skip to content

Instantly share code, notes, and snippets.

@artbah
Created July 27, 2018 03:33
Show Gist options
  • Save artbah/8327595227914bba0535bb889ed5628b to your computer and use it in GitHub Desktop.
Save artbah/8327595227914bba0535bb889ed5628b to your computer and use it in GitHub Desktop.
Animated - Button
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<defs>
<symbol id="arrow" viewBox="0 0 100 100">
<path d="M12.5 45.83h64.58v8.33H12.5z"/>
<path d="M59.17 77.92l-5.84-5.84L75.43 50l-22.1-22.08 5.84-5.84L87.07 50z"/>
</symbol>
</defs>
</svg>
<div class="container">
<div class="content">
<a href="#" class="button">
Button Text
<span>
<svg>
<use xlink:href="#arrow" href="#arrow"></use>
</svg>
</span>
</a>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Droid+Serif');
$button-color: #4A90E2;
$transition-time: 750ms;
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: #ededed;
font-family: 'Droid Serif', serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.button {
position: relative;
display: inline-flex;
text-decoration: none;
color: #fff;
background-color: lighten($button-color, 10%);
padding-left: 2rem;
overflow: hidden;
z-index: 1;
align-items: center;
box-shadow: 0px 3px 4px -4px rgba(0,0,0,0.75);
&::before {
content: '';
position: absolute;
left: 0;
top: 0;
transform: scaleX(0);
transform-origin: 0 50%;
width: 100%;
height: 100%;
background-color: $button-color;
z-index: -1;
transition: transform $transition-time;
}
span {
display: flex;
align-items: center;
justify-content: center;
margin-left: 2rem;
padding: 1rem;
overflow: hidden;
background-color: $button-color;
}
svg {
max-width: 20px;
width: 100%;
height: auto;
max-height: 18px;
fill: white;
}
&:hover {
&::before {
transform: scaleX(1);
}
svg {
animation: moveArrow $transition-time;
}
}
}
@keyframes moveArrow {
0% {
transform: translateX(0px);
}
49% {
transform: translateX(50px);
}
50% {
transform: translateX(-50px);
}
100% {
transform: translateX(0px);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment