JSFiddle - React, Tailwind, and code Playground

by bestiole

HTML

<div></div>

CSS

div {
  width:50px;
  height:50px;
  background-color:red;
  position:fixed;
}

JavaScript

var speed = 0.04;
var amplitude = 80;
var offset = 100;

var time = 0;
var div;
var x,y;

$(document).ready(function(){
    div = $('div');
    animateDiv();
});

function animateDiv(){
    time += speed;
    x = amplitude * Math.sin(time) * Math.cos(time);
    y = amplitude * Math.sin(time);
    div.css({'top':x+offset,'left':y+offset});
    requestAnimationFrame(animateDiv);
}