如何准确跟踪窗户上的鼠标运动?
现在,我正在通过一种方法来根据鼠标是否向下以及鼠标是否超过元素来更新元素状态。这意味着,一旦鼠标向下,每次鼠标悬停在其中一个元素上时,状态就会发生变化。跟踪是不准确的,它不会捕获每个动作。我如何改善过程?
我目前的暗示代码是:
document.onmousedown = () => {
document.onmousemove = (e) => {
if (e.buttons === 1) {
let svg = e.target as HTMLElement;
if (svg.id.startsWith('svg')) {
let SVG_ID = svg.id;
let HoverPropsID = svg.id.replace('svg', 'props');
if (document.getElementById(HoverPropsID).classList.contains('no-node')) {
toRemove.forEach(element => document.getElementById(SVG_ID).classList.remove(element));
document.getElementById(SVG_ID).classList.add(`svg-${node}`);
document.getElementById(HoverPropsID).classList.remove('no-node');
document.getElementById(HoverPropsID).classList.add(node);
multiNodeGraphUpdate(node, Number(HoverPropsID.substring(HoverPropsID.lastIndexOf('-') + 1)), 10, false)
}
nodeHoverAnimation(HoverPropsID);
}
}
}
我了解我提供的信息可能是一个很大的模棱两可,因此我链接了两个网站,一个是灵感网站: https://clementmihailescu.github.io/pathfinding-visalizer/
,另一个是Wip webiste(我自己): https://aarnavv.github.io/vagus/
Right now I am working on a way to update the state of an element based on whether the mouse is down as well as whether the mouse is over the element. This means that once the mouse is down, every time it hovers over one of the elements, the state changes. The tracking is inaccurate, it does not capture every single action. How do I improve the process?
The code for my present implmentation is:
document.onmousedown = () => {
document.onmousemove = (e) => {
if (e.buttons === 1) {
let svg = e.target as HTMLElement;
if (svg.id.startsWith('svg')) {
let SVG_ID = svg.id;
let HoverPropsID = svg.id.replace('svg', 'props');
if (document.getElementById(HoverPropsID).classList.contains('no-node')) {
toRemove.forEach(element => document.getElementById(SVG_ID).classList.remove(element));
document.getElementById(SVG_ID).classList.add(`svg-${node}`);
document.getElementById(HoverPropsID).classList.remove('no-node');
document.getElementById(HoverPropsID).classList.add(node);
multiNodeGraphUpdate(node, Number(HoverPropsID.substring(HoverPropsID.lastIndexOf('-') + 1)), 10, false)
}
nodeHoverAnimation(HoverPropsID);
}
}
}
I understand that the information I have provided might be a big ambiguous, so I am linking two websites, one is the inspiration website: https://clementmihailescu.github.io/Pathfinding-Visualizer/
and the other one is the WiP webiste (my own): https://aarnavv.github.io/Vagus/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论