JSFiddle - React, Tailwind, and code Playground

HTML

<div id="square">
    asd
</div>

CSS

#square {
    width: 25px; height: 25px;
    padding: 25px;
    background: red;
    color: #fff;
    position: absolute;
    top: 50px; left: 100px;
}

JavaScript

$(function() {
    var $square = $("#square"),flag = 1;
    var timer;
    bounce();
    function bounce() {
        timer = setInterval(function() {
                   if(flag ==1) {
                        flag = -1;
                    } else {
                        flag = 1;
                    }
                    $square.animate({ top: "+="+(flag*10)}, 300)
                },300);
    }               

    $square.hover(function() {       
        clearInterval(timer);
    }, function() {
        bounce();
    });
});