1
When the mouse movement is fast it ends up leaving the square and so the square does not move together with the mouse, I would like to know a solution so that the square always accompanies the mouse independent of it leaving the field of the square with the cursor dragging it.
#bloco{
width: 100px;
height: 100px;
background-color: orangered;
position: absolute;
}
<div id="bloco"></div>
<script>
bloco.style.top = 10+"px"
bloco.style.left = 10+"px"
bloco.onmousemove=function(e){
x = e.movementX
y = e.movementY
if( e.buttons > 0 ){
bloco.style.top = (parseInt(bloco.style.top)+y)+"px"
bloco.style.left = (parseInt(bloco.style.left)+x)+"px"
}
}
bloco.onmouseout=function(e){
// k = 0;
}
</script>
Maybe it is better not to link the Mousemove to the block, but to start the movement in the click, independent of the "Hover", following the mouse in the whole page.
– Bacco
I think there’s something here that looks like what you want, but it was done with jQuery... https://answall.com/questions/312832/algu%C3%A9m-could-tell me-how-can-do-this-effect-to-pass-the-mouse/312864#312864
– hugocsl