JSFiddle - React, Tailwind, and code Playground

by flaprogrammer

HTML

<div class="box playing"></div>

CSS

.box {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #cc4499;
}

.box.playing {
    -webkit-animation-name: move;
	-webkit-animation-duration: 1s;
	-webkit-animation-timing-function: linear;
}

@-webkit-keyframes move {
    0% {
        -webkit-transform: translateX(0);
    }
    100% {
        -webkit-transform: translateX(200px);
    }
}

JavaScript

$('.box').on('animationend', function(e){
    var top = 20 + Math.random()*100;
    var ad = 1 + Math.random()*5;
    $(this).removeClass('playing');    
    $('.box').scrollTop(0).addClass('playing');
    $(this).css('top', top);
    $(this).css('-webkit-animation-duration', parseInt(ad)+'s');
});