JSFiddle - React, Tailwind, and code Playground

by mblase75

HTML

<div id="ball"></div>

CSS

#ball {
    background: blue;
    width: 60px;
    height: 60px;
    position: absolute;
    top: 100px;
    left: 30px;
}

JavaScript

function bounce(n, callback) {
    if (n > 0) {
        $("#ball").animate({top: "-=5px"}, 150)
            .animate({top: "+=5px"}, 150, function () {
                bounce(n-1, callback);
            });
    } else if (callback) {
        callback();
    }
};

bounce(3, function() {
    $("#ball").animate({"left": "850px"}, 2800).dequeue();
    bounce(10);
});