Javascript 我可以将鼠标坐标的零点设置在指定容器的中心,而不是其拐角处吗?
在本主题中,这个零点是否可以从页面的一角更改为我指定的点?我目前正在研究跟踪光标移动的眼睛,问题是眼睛只能在全范围内向右和向下看。元素实际上根本不会向上或向左移动,这是鼠标线的默认零点。在我看来,这个问题是因为零点默认位于容器的左上角(X:0,Y:0)。 下面我将发送到目前为止我已经开发的代码Javascript 我可以将鼠标坐标的零点设置在指定容器的中心,而不是其拐角处吗?,javascript,coordinates,mouseevent,mouse-position,Javascript,Coordinates,Mouseevent,Mouse Position,在本主题中,这个零点是否可以从页面的一角更改为我指定的点?我目前正在研究跟踪光标移动的眼睛,问题是眼睛只能在全范围内向右和向下看。元素实际上根本不会向上或向左移动,这是鼠标线的默认零点。在我看来,这个问题是因为零点默认位于容器的左上角(X:0,Y:0)。 下面我将发送到目前为止我已经开发的代码 landingContainer.addEventListener('mousemove', e => { // container on which the cursor moves c
landingContainer.addEventListener('mousemove', e => { // container on which the cursor moves
const leftEye = document.querySelector('.leftBuddyEye'); // node list where eye is index nr. 1
const rightEye = document.querySelector('.rightBuddyEye');// ---...---
let x = e.x * 20 / window.innerWidth + '%';
let y = e.y * 40 / window.innerHeight + '%';
let thisLeftEye = leftEye.childNodes;
thisLeftEye[1].style.left = x;
thisLeftEye[1].style.top = y;
let z = e.x * 15 / window.innerWidth + 80 + '%'; //I had to make some corrections here to keep the eye in place. Without adding 80 to width, the right eye would shift under the left eye.
let v = e.y * 40 / window.innerHeight + '%';
let thisRightEye = rightEye.childNodes; // The same as before.
thisRightEye[1].style.left = z;
thisRightEye[1].style.top = v;
})
如何更改默认启动坐标?你怎么认为?这应该解决这个问题吗