Skip to content

Instantly share code, notes, and snippets.

@LaunchedBerry07
Created August 24, 2022 13:27
Show Gist options
  • Save LaunchedBerry07/51d7cc14addbdd093c593531542080bc to your computer and use it in GitHub Desktop.
Save LaunchedBerry07/51d7cc14addbdd093c593531542080bc to your computer and use it in GitHub Desktop.
Animated Ghost Button
<link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<div class="button">
<a href="#">
Often Unseen
<span class="shift">›</span>
</a>
<div class="mask"></div>
</div>
const body = document.body;
const btn = document.querySelectorAll('.button')[0];
btn.addEventListener('mouseenter', () => {
body.classList.add('hover');
});
btn.addEventListener('mouseleave', () => {
body.classList.remove('hover');
});
:root {
--bg-body: rgba(32, 32, 32, 1);
--bg-body-image: radial-gradient(30% 90% ellipse at bottom center, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 100%);
--bg-body-hover: rgba(40, 40, 40, 1);
--bg-button: rgba(255, 255, 255, 0);
--bg-button-hover: rgba(255, 255, 255, 0.05);
--bg-button-active: rgba(255, 255, 255, 1.0);
--bg-mask: rgba(255, 255, 255, 0.5);
--bg-mask-hover: rgba(255, 255, 255, 1.0);
--border-button: rgba(255, 255, 255, 0.2);
--border-button-hover: rgba(255, 255, 255, 1.0);
--color-button: rgba(255, 255, 255, 0.6);
--color-button-hover: rgba(255, 255, 255, 1.0);
--color-button-active: var(--body-bg);
--font-button: "Varela Round", sans-serif;
--shadow-button-hover: 0 0 0.3125rem rgba(255, 255, 255, 0.8);
}
body {
align-items: center;
background-color: var(--bg-body);
background-image: var(--bg-body-image);
display: flex;
height: 100vh;
justify-content: center;
margin: 0;
padding: 0;
transition: background-color 2s cubic-bezier(0.19, 1, 0.22, 1);
}
body.hover {
background-color: var(--bg-body-hover);
}
.button {
background-color: var(--bg-button);
border: 0.125rem solid var(--border-button);
cursor: pointer;
letter-spacing: 0.2125rem;
line-height: 1;
overflow: hidden;
padding: 1.25rem 1.875rem;
position: relative;
text-align: center;
text-transform: uppercase;
transition:
background-color 0.2s cubic-bezier(0.19, 1, 0.22, 1),
border 1s cubic-bezier(0.19, 1, 0.22, 1),
color 0.6s cubic-bezier(0.19, 1, 0.22, 1);
user-select: none;
}
.button a {
color: var(--color-button);
font-family: var(--font-button);
text-decoration: none;
white-space: nowrap;
}
.button .mask {
background-color: var(--bg-mask);
height: 6.25rem;
position: absolute;
transform: translate3d(-120%, -50px, 0) rotate3d(0, 0, 1, 45deg);
transition: all 1.1s cubic-bezier(0.19, 1, 0.22, 1);
width: 12.5rem;
}
.button .shift {
display: inline-block;
transition: all 1.1s cubic-bezier(0.19, 1, 0.22, 1);
vertical-align: text-top;
}
.button:hover {
background-color: var(--bg-button-hover);
border-color: var(--border-button-hover);
box-shadow: var(--shadow-button-hover);
}
.button:hover a {
color: var(--color-button-hover);
}
.button:hover .mask {
background-color: var(--bg-mask-hover);
transform: translate3d(120%, -100px, 0) rotate3d(0, 0, 1, 90deg);
}
.button:hover .shift {
transform: translateX(0.3125rem);
}
.button:active {
background-color: var(--bg-button-active);
}
.button:active a {
color: var(--color-button-active);
}
/*
.button:hover {
background-image: url('http://.com/img/codepen/savvy.jpg');
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment