JSFiddle - React, Tailwind, and code Playground

by nazarpunk

HTML

<div></div>

CSS

div {
  position: fixed;
  width: 30px;
  height: 30px;
  background: red;
}

JavaScript

let x = 0,
  y = 0;

addEventListener('mousemove', e => {
  x = e.pageX;
  y = e.pageY;
})

const div = document.querySelector('div');

setInterval(() => {
  div.style.left = `${x-15}px`;
  div.style.top = `${y-15}px`;
},100);