Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Last active January 1, 2022 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeMyUI/7944c736558f04bd450dc4735253c4de to your computer and use it in GitHub Desktop.
Save CodeMyUI/7944c736558f04bd450dc4735253c4de to your computer and use it in GitHub Desktop.
Button Hover Effects #2
<button class="button">Jumping</button>
<button class="button smoke dark">Smoke</button>
<button class="button drive white">Drive</button>
<!-- dribbble - twitter -->
<a class="dribbble" href="https://dribbble.com/shots/8764233-Button-Hover-Effects-2" target="_blank"><img src="https://cdn.dribbble.com/assets/dribbble-ball-mark-2bd45f09c2fb58dbbfb44766d5d1d07c5a12972d602ef8b32204d28fa3dda554.svg" alt=""></a>
<a class="twitter" target="_blank" href="https://twitter.com/aaroniker_me"><svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" viewBox="0 0 72 72"><path d="M67.812 16.141a26.246 26.246 0 0 1-7.519 2.06 13.134 13.134 0 0 0 5.756-7.244 26.127 26.127 0 0 1-8.313 3.176A13.075 13.075 0 0 0 48.182 10c-7.229 0-13.092 5.861-13.092 13.093 0 1.026.118 2.021.338 2.981-10.885-.548-20.528-5.757-26.987-13.679a13.048 13.048 0 0 0-1.771 6.581c0 4.542 2.312 8.551 5.824 10.898a13.048 13.048 0 0 1-5.93-1.638c-.002.055-.002.11-.002.162 0 6.345 4.513 11.638 10.504 12.84a13.177 13.177 0 0 1-3.449.457c-.846 0-1.667-.078-2.465-.231 1.667 5.2 6.499 8.986 12.23 9.09a26.276 26.276 0 0 1-16.26 5.606A26.21 26.21 0 0 1 4 55.976a37.036 37.036 0 0 0 20.067 5.882c24.083 0 37.251-19.949 37.251-37.249 0-.566-.014-1.134-.039-1.694a26.597 26.597 0 0 0 6.533-6.774z"></path></svg></a>
document.querySelectorAll('.button').forEach(button => button.innerHTML = '<div><span>' + button.textContent.trim().split('').join('</span><span>') + '</span></div>');
.button {
&.dark {
--background: #2F3545;
--shadow: 0 2px 8px -1px #{rgba(#151924, .32)};
--shadow-hover: 0 4px 20px -2px #{rgba(#151924, .5)};
}
&.white {
--background: #fff;
--text: #275efe;
--shadow: 0 2px 8px -1px #{rgba(#121621, .04)};
--shadow-hover: 0 4px 20px -2px #{rgba(#121621, .12)};
}
}
.button {
--background: #275efe;
--text: #fff;
--font-size: 16px;
--duration: .5s;
--move-hover: -4px;
--shadow: 0 2px 8px -1px #{rgba(#275efe, .32)};
--shadow-hover: 0 4px 20px -2px #{rgba(#275efe, .5)};
padding: 16px 32px;
font-family: 'Roboto';
font-weight: 500;
line-height: var(--font-size);
border-radius: 24px;
display: block;
outline: none;
border: none;
cursor: pointer;
text-decoration: none;
font-size: var(--font-size);
letter-spacing: .5px;
background: var(--background);
color: var(--text);
box-shadow: var(--shadow);
transform: translateY(var(--y));
transition: transform var(--duration) ease, box-shadow var(--duration) ease;
-webkit-tap-highlight-color: transparent;
-webkit-appearance: none;
div {
display: flex;
span {
display: block;
backface-visibility: hidden;
font-style: normal;
$i: 1;
@while $i < 12 {
&:nth-child(#{$i}) {
--d: #{$i / 20 + s};
}
$i: $i + 1;
}
}
}
&:hover {
--y: var(--move-hover);
--shadow: var(--shadow-hover);
--move: -4px;
--shadow-active: 0 3px 1px rgba(0, 0, 0, .2);
span {
animation: move var(--duration) linear var(--d);
}
}
&.smoke {
--move: 12px;
--move-y: -8px;
--blur: 4px;
&:hover {
span {
--duration: 1s;
animation: smoke var(--duration) linear var(--d);
}
}
}
&.drive {
--move: 16px;
--skew: 25deg;
--skew-fast: 40deg;
--skew-bounce: -12px;
&:hover {
span {
--duration: 1s;
transform-origin: 50% 100%;
animation: drive var(--duration) linear var(--d);
}
}
}
}
@keyframes move {
40% {
transform: translateY(var(--move));
text-shadow: var(--shadow-active);
}
}
@keyframes smoke {
45%,
55% {
filter: blur(var(--blur));
}
50%,
50.1% {
opacity: 0;
}
25%,
75% {
transform: translateX(0);
}
50% {
transform: translateX(var(--move)) translateY(var(--move-y));
}
50.1% {
transform: translateX(calc(var(--move) * -1));
}
}
@keyframes drive {
40% {
opacity: 1;
}
55% {
transform: skewX(var(--skew)) translateX(var(--move));
}
56% {
transform: skewX(var(--skew-fast)) translateX(calc(var(--move) * -1));
}
55%,
56% {
opacity: 0;
}
75% {
transform: skewX(var(--skew));
}
85% {
transform: skewX(var(--skew-bounce));
}
}
html {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
}
* {
box-sizing: inherit;
&:before,
&:after {
box-sizing: inherit;
}
}
// Center & dribbble
body {
min-height: 100vh;
display: flex;
font-family: 'Roboto', Arial;
justify-content: center;
align-items: center;
background: #ECEFFC;
.button {
margin: 0 12px;
}
.dribbble {
position: fixed;
display: block;
right: 20px;
bottom: 20px;
img {
display: block;
height: 28px;
}
}
.twitter {
position: fixed;
display: block;
right: 64px;
bottom: 14px;
svg {
width: 32px;
height: 32px;
fill: #1da1f2;
}
}
}
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&amp;display=swap" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment