JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

HTML

requestAnimationFrame:
<div id='anim'></div>
<br/>mousemove:
<div id='move'></div>

JavaScript

var a = 0,
    diva = document.getElementById('anim'),
    b = 0,
    c=0,
    divb = document.getElementById('move'),
    position = [0,0],
    anim = function (e) {
              diva.style.top = position[1]+'px';
        diva.style.left = position[0]+'px';
        requestAnimationFrame(anim);
        diva.textContent =Math.round( e - a);
         divb.textContent=c;
        a = e;
  
    };
var mousemovefunction = function (e) {
    if (b === 0) {
        b = e.timeStamp;
    }
            position = [e.pageX,e.pageY];
           c = e.timeStamp - b;
            b = e.timeStamp;
    
};
window.addEventListener('mousemove', mousemovefunction);
requestAnimationFrame(anim);