gpt4 book ai didi

javascript - 确定鼠标在窗口焦点事件上的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:58 25 4
gpt4 key购买 nike

我已将焦点监听器附加到窗口(使用原型(prototype)语法):

Event.observe( window, 'focus', focusCb.bindAsEventListener( this ) );

我想确定窗口聚焦时的鼠标位置。不幸的是,在我的 focusCb 方法中,我似乎无法访问 pageX、pageY、clientX 或 clientY。

使用 quirksmode代码:

function doSomething(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}

// posx and posy contain the mouse position relative to the document
// Do something with this information
}

我总是得到 0, 0。

我以为焦点事件会有鼠标位置信息。

  1. 为什么焦点事件没有此信息?
  2. 更重要的是,当窗口获得焦点时我应该如何获得鼠标位置?

最佳答案

IE 在 event object 中有 clientX 和 clientY ;尽管它可能是唯一的。

是的,这看起来很糟糕。请参阅有关 this page 的部分关于鼠标位置。我认为他在检查方面做得非常彻底。

好的,我知道您实际上已经在使用他的脚本了。叹息。

关于javascript - 确定鼠标在窗口焦点事件上的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1697352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com