JSFiddle - React, Tailwind, and code Playground

by ronilan

HTML

Move Me with mouse (raw js)
<div id="move-me" class="move-me">
</div>

CSS

.move-me{
  width: 100px;
  height: 100px;
  background: pink;
  position: fixed;
}

JavaScript

var el = document.getElementById('move-me');

el.addEventListener('click', function () {
	el.style.backgroundColor = '#'+Math.floor(Math.random()*16777215).toString(16);
});


document.addEventListener('mousemove', function (e) {
	el.style.top = e.y - el.offsetHeight/2 + 'px';
	el.style.left = e.x - el.offsetWidth/2 + 'px';
});