JSFiddle - React, Tailwind, and code Playground
HTML
<div></div>
CSS
div {
background: #000;
height: 100px;
left: 0;
margin: 50px auto;
position: absolute;
right: 0;
top: 0;
width: 100px;
}
JavaScript
var theX = 0, lastX = 0;
$('body, html').mousemove(function (e) {
theX = e.pageX;
});
function c2p( x ) {
return - (x - ($(document).width() / 2)) * 0.3
}
setInterval( function() {
var x = c2p( theX ), cx = (lastX + x)/2;
console.log( cx );
$('div').css('left', cx );
lastX = cx;
}, 100 );