JSFiddle - React, Tailwind, and code Playground
HTML
<div class="wrap">
<div class="text">Click the box</div>
<div class="box" style="transform: scale(1)"></div>
</div>
CSS
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.wrap {
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
.box {
width: 100px;
height: 100px;
background: bisque;
position: absolute;
transform: scale(1);
cursor: pointer;
}
.text {
color: white;
position: absoulte;
z-index: 1;
margin-top: 25px;
align-self: flex-start;
font-family: sans-serif;
user-select: none;
}
JavaScript
import anim from 'https://unpkg.com/slim-anim@1.0.0/index.js'
const box = document.querySelector('.box')
window.addEventListener('load', function() {
box.addEventListener('click', function() {
if (!box.toggled) anim(box, { transform: 'scale(3)', borderRadius: '100px' }, { duration: 250 })
else anim(box, { transform: 'scale(1)', borderRadius: '0px' }, { duration: 350 })
box.toggled = !box.toggled
})
})