Javascript 为什么通过mousemove旋转div不工作?

Javascript 为什么通过mousemove旋转div不工作?,javascript,rotation,mousemove,mousedown,degrees,Javascript,Rotation,Mousemove,Mousedown,Degrees,我想让div从0旋转到360,而不带-。旋转方向应为顺时针方向,从0到360度。在该代码中,旋转范围为0到180,从-180到0 第二个问题:每次我点击“rotator div”,我的位置都会改变 代码: document.getElementById(“旋转器”).addEventListener(“mousedown”,mouseDownRotator,false); 功能鼠标向下旋转器(e){ addEventListener(“mousemove”,mouseMoveRotator,t

我想让div从0旋转到360,而不带-。旋转方向应为顺时针方向,从0到360度。在该代码中,旋转范围为0到180,从-180到0

第二个问题:每次我点击“rotator div”,我的位置都会改变

代码:

document.getElementById(“旋转器”).addEventListener(“mousedown”,mouseDownRotator,false);
功能鼠标向下旋转器(e){
addEventListener(“mousemove”,mouseMoveRotator,true);
}
功能鼠标翻转器(e){
window.addEventListener('mouseup',mouseUpRotator,true);
var arrow=document.getElementById(“旋转器”);
var arrowRects=document.getElementById(“dragdiv”).getBoundingClientRect();
var center_x=(arrowRects.left)+(arrowRects.width/2);
变量中心y=(arrowcrects.top)+(arrowcrects.height/2);
var mouse_x=e.pageX;
var mouse_y=e.pageY;
var radians=Math.atan2(鼠标x-中心x,鼠标y-中心y);
document.getElementById(“dragdiv”).style.transform=“旋转(“+(弧度*(180/Math.PI)*-1)+90+”度)”;
}
函数mouseUpRotator(){
removeEventListener(“mousemove”,mouseMoveRotator,true);
}
#dragdiv{
宽度:100px;
高度:100px;
背景色:红色;
位置:绝对位置;
利润率:250像素;
}
#旋转器{
宽度:10px;
高度:10px;
边界半径:50%;
背景:白色;
边框:3px实心#4286f4;
位置:绝对位置;
顶部:-50px;
右:43%;
光标:nwse调整大小;
}


当您移动从源代码复制的鼠标以缩短它时,该代码将添加大量事件,因此可能有我不需要的内容。欢迎提出建议和改变。。