var div = document.getElementById('circle'); var listener = function(e) { div.style.left = e.pageX + "px"; div.style.top = e.pageY + "px"; }; function move() { document.addEventListener('mousemove', listener); } function stop() { document.removeEventListener('mousemove', listener); } .block1 { width: 100px; height: 100px; position: absolute; left: 50px; top: 50px; border-radius: 50%; background: blue; } <div class="block1" id="circle" onMouseDown="move()" onKeyDown="stop()"> </div>
onmouseupis not called on the circle, because he does not catch this event. Make the circle exactly under the cursor (for example,e.pageX -50 + "px"; e.pageY -50 + "px"- move it to thelistener) and thenonmouseupwill be caught around - BOPOH