JSFiddle - React, Tailwind, and code Playground
by lollero
HTML
<button>asdfasdf</button>
<div class="test">test</div>
JavaScript
var loop = 3000;
// Run the animation once
myA();
// Loop animation
var myInterval = setInterval( myA,loop );
// Pause animation on click
$('button').on({
mouseenter: function() {
clearInterval( myInterval );
},
mouseleave: function() {
myA();
var myInterval = setInterval( myA,loop );
}
});
function myA() {
$('.test').animate({ marginLeft: 400 }, loop, function() {
$('.test').css({ marginLeft: 0 });
});
}