JSFiddle - React, Tailwind, and code Playground
HTML
<div class='test'>test</div>
CSS
.test{
height:500px;
width: 500px;
}
JavaScript
// Флаг нажатия кнопки
is_active = false;
// Зажата клавиша мыши
window.onmousedown = function(){
is_active = true;
}
// Отпущена клавиша мыши
window.onmouseup = function(){
is_active = false;
}
var x = 0, y = 0;
var body = document.getElementsByTagName("body")[0];
body.onmousemove = function(event){myScript(event);};
function myScript(e){
if(is_active){
var c_x = e.clientX;
var c_y = e.clientY;
if(x < c_x){
console.log("двигаемся вправо");
x = c_x;
}
else if (x > c_x){
console.log("двигаемся влево");
x = c_x;
}
else console.log("стоим");
console.log(e);
}
};