JSFiddle - React, Tailwind, and code Playground
by EstSiim
HTML
<div class="box"></div>
<button class="animate-btn">Animate</button>
CSS
.box {
background-color: red;
width: 200px;
height: 200px;
margin-bottom:10px;
}
.box:hover {
background-color: blue;
}
.trigger-bg-change {
-webkit-animation: bg-change 1s ease 0 1 forwards;
animation: bg-change 1s ease 0 1 forwards;
}
@-webkit-keyframes bg-change {
0% {background-color:red;}
100% {background-color:green;}
}
@-keyframes bg-change {
0% {background-color:red;}
100% {background-color:green;}
}
JavaScript
$(function() {
$('.animate-btn').on('click', function() {
console.log('hey');
$('.box').addClass('trigger-bg-change');
});
});