我正在尝试根据箭头要去的位置来计算球上箭头的角度。箭头移动,但完全无法解释的方向,有人可以指点一下吗?
可用代码笔:代码笔
我在这里添加了完整的代码(根据输入进行编辑):我添加了一个步骤以使角度计算的差异更大,不确定这是否是正确的方法,但它似乎更实用。另外在角度方法中添加了+/- 90,但这似乎并不能解决问题。感觉还是很奇怪。
class Throwable {
constructor(){
this.throwObject = null;
this.canDrag = null;
this.initialDiffX = 0;
this.initialDiffY = 0;
this.previousX = 0;
this.previousY = 0;
this.intervalCounter = 0;
}
set x(input) {
this.throwObject.style.left = input + 'px';
}
set y(input) {
this.throwObject.style.top = input + 'px';
}
set rotation(input) {
this.throwObject.style.transform = `rotate(${input}deg)`;
}
init(){
this.throwObject = document.querySelector('.throwable');
this.throwObject.addEventListener('mousedown', this.activateDrag.bind(this));
this.throwObject.addEventListener('mouseup', this.deactivateDrag.bind(this));
document.addEventListener('mousemove', this.drag.bind(this));
}
activateDrag(event) {
this.canDrag = true;
this.initialDiffX = event.clientX - this.throwObject.offsetLeft;
this.initialDiffY = event.clientY …Run Code Online (Sandbox Code Playgroud)