Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teethnclaws/2550c05230af4a9a20ed6cddddd47aad to your computer and use it in GitHub Desktop.
Save teethnclaws/2550c05230af4a9a20ed6cddddd47aad to your computer and use it in GitHub Desktop.
Implementation of Liquid button
.background
.toggle-body
.toggle-btn
const background = document.querySelector('.background');
const toggleBody = document.querySelector('.toggle-body');
const toggleBtn = document.querySelector('.toggle-btn');
toggleBtn.addEventListener('click', () => {
background.classList.toggle('background--on');
toggleBody.classList.toggle('toggle-body--on');
toggleBtn.classList.toggle('toggle-btn--on');
toggleBtn.classList.toggle('toggle-btn--scale');
});
$green: #3dbf87;
$red: #FC3164;
$animtime: 1.5s;
$easing: cubic-bezier(0.68, -0.15, 0.265, 1.35);
$iteration: 1;
.background {
width: 100vw;
height: 100vh;
position: relative;
background: $red;
transition: 1.5s $easing;
}
.background--on {
background: $green;
transition: 1.5s $easing;
}
.toggle-body {
width: 7rem;
height: 4rem;
position: absolute;
top: calc(50% - 4rem / 2);
left: calc(50% - 7rem / 2);
background: white;
border-radius: 2rem;
transform: rotate(0deg);
transition: $animtime $easing;
}
.toggle-body--on {
transform: rotate(180deg);
transition: $animtime $easing;
}
.toggle-btn {
width: 2rem;
height: 2rem;
position: absolute;
top: calc(50% - 2rem / 2);
left: calc(27% - 2rem / 2);
background: white;
border-radius: 2rem;
background: $red;
cursor: pointer;
transform: rotate(0deg);
transform-origin: 130% 115%;
transition: $animtime $easing;
}
.toggle-btn--on {
transition: $animtime $easing;
transform: rotate(-357deg);
background: $green;
transform-origin: 130% 150%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment