When the movement of the mouse is rapid it ends up leaving the square and thus the square does not move along with the mouse, I would like to know a solution so that the square always accompanies the mouse independent of him leaving the field of the square with the cursor o by dragging.
#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>