I'm a beginner to JavaScript and animation in general. I recently spent a ridiculous amount of time scouring the internet looking for just a simple basic button-click animation so that a Phonegap app I am working wouldn't look so flat and would react a little bit to the user. I also needed something readable for a beginner like me so I would better understand the idea. I finally came up with something and thought I would share it. Hopefully someone will find this helpful. See code below.
function animateButton(elem, callback) {
var perc = 0; // Initially radial background is not visible
var id = setInterval(function() {
if (perc >= 100) {
// Change "rgba(194, 194, 194, 1)" to whatever color you want the effect to be
// Change "rgba(255, 255, 255, 1)" to whatever color the background is
$(elem).css('background', 'radial-gradient(circle, rgba(194,194,194,1) 0%, rgba(255,255,255,1) 100%)');
clearInterval(id);
callback();
} else {
$(elem).css('background', 'radial-gradient(circle, rgba(194,194,194,1) 0%, rgba(255,255,255,1) ' + perc + '%)');
perc = perc + 3;
}
}, 1)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div onclick="animateButton(this, () => { alert('Callback')})">Button</div>