JSFiddle - React, Tailwind, and code Playground

by lukempeters

HTML

<div class="ball"></div>

CSS

body {
    margin: 100px 0 0 100px;
}

div.ball {
    width: 100px;
    height: 100px;
    border-radius: 100px;
    cursor: pointer;
    background: #66dd88;
}

JavaScript

function doStuff() {
    $('.ball').animate({
        'marginTop': '-=10px'
    }, 200).delay(200).animate({
        'marginTop': '+=10px'
    }, 200);
}
    
$(function() {
    $(".ball").hover(
        function() {
            // call doStuff every 100 milliseconds
            hoverInterval = setInterval(doStuff, 100);
        },
        function() {
            // stop calling doStuff
            clearInterval(hoverInterval);
        }
    );
});