JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" id="toggle">Toggle</a>
CSS
.pulse {
width: 100px;
height: 100px;
background-color: red;
}
JavaScript
(function toggler() {
var temp;
var running = false;
var myfunc = function() {
$('<div class="pulse"/>').appendTo('body').fadeOut(function() {
$(this).animate({margin:'+=6px'},300)
});
running = true;
temp = setTimeout(myfunc, 1000);
}
$('#toggle').click(function(e) {
e.preventDefault();
if (running) {
clearTimeout(temp);
running = false;
} else {
myfunc();
}
});
myfunc();
})();