JSFiddle - React, Tailwind, and code Playground

HTML

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

CSS

#div {
  background:#009CBA;
  height:40px;
  width:40px;
  position:absolute;
  border-radius:25px;
}

JavaScript

$(document).ready(function(){
    $("#div").hover(function(){
			var x = $("#div")
      for (y = 1; y <= 100; y++){
          var random = Math.floor((Math.random() * 4) + 1);     //směr
          var pozice = Math.floor((Math.random() * 100) + 10);  //posun

					switch (random) {
          	case 1:
            case 2:
            	x.css("background","yellow").animate({'left':pozice});
            	break;
            case 3:
            	x.css("background","blue").animate({'left':pozice});
            	break;
            case 4:
            	x.css("background","red").animate({'top':pozice})
            	break;
          }
      }
    });
});