这段代码第一次执行的时候正常,但第二次就无效,求解
var cir = document.getElementsByClassName("circle")[0];
cir.onmousedown = function( event ){
var disX = event.clientX - cir.offsetLeft;
var disY = event.clientY - cir.offsetTop;
document.onmousemove = function( event ){
cir.style.left = ( event.clientX - disX ) + "px";
cir.style.top = ( event.clientY - disY ) + "px";
return false;
}
}
document.onmouseup = function(){
cir.onmousedown = null;
document.onmousemove = null;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你为啥要在
onmouseup中把cir.onmousedown置为null? 注释掉这行试试修改后的代码: http://codepen.io/anon/pen/vX...
因为你鼠标松开事件设置了
cir.onmousedown = null;document.onmousemove = null;你都取消了还怎么可能有效呢