JSFiddle - React, Tailwind, and code Playground
HTML
<div class="outside">
<div class="inside">
</div>
</div>
CSS
.outside {
border: 1px solid magenta;
height: 100px;
width: 100px;
position: relative;
}
.inside {
border: 1px solid skyblue;
height: 60px;
width: 60px;
margin-top: -31px;
margin-left: -31px;
position: absolute;
top: 50%;
left: 50%;
}
.outside.animate {
-webkit-animation-delay: 0s, .5s, .5s;
-webkit-animation-duration: 500ms, 1000ms, 1000ms;
-webkit-animation-name: button-bounce, rotate, skyblue;
}
.animate {
-webkit-animation-fill-mode: forwards;
-webkit-animation-timing-function: ease;
-webkit-transform: translateZ(0);
}
.outside.animate .inside {
-webkit-animation-delay: .5s, .5s, 1.5s;
-webkit-animation-duration: 1000ms, 1000ms, 750ms;
-webkit-animation-name: rotate, magenta, scale-in;
}
@-webkit-keyframes scale-in {
0% { -webkit-transform: scale(0); }
100% { -webkit-transform: scale(1); }
}
@-webkit-keyframes button-scale-in {
0% { -webkit-transform: scale(0); }
100% { -webkit-transform: scale(1); }
}
@-webkit-keyframes button-bounce {
0% { -webkit-transform: scale(1); }
25% { -webkit-transform: scale(.8); }
50% { -webkit-transform: scale(1); }
75% { -webkit-transform: scale(.9); }
100% { -webkit-transform: scale(1); }
}
@-webkit-keyframes rotate {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@-webkit-keyframes magenta {
0% { border: 1px solid magenta; }
99.99% { border: 1px solid magenta; }
100% { border: 1px solid skyblue; }
}
@-webkit-keyframes skyblue {
0% { border: 1px solid skyblue; }
99.99% { border: 1px solid skyblue; }
100% { border: 1px solid magenta; }
}
JavaScript
$(document).ready(function() {
$(document).click(function() {
var count = 0;
var jqElement = $('.outside');
if (!jqElement.hasClass('animate')) {
jqElement.addClass('animate');
jqElement.on('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd', function(event) {
count++;
if (count >= 6) {
jqElement.off('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd');
jqElement.removeClass('animate');
}
});
}
});
});