event.screenX 和外部 Javascript
我目前正在尝试使用“
function getCursor(event) {
event.screenX;
event.screenY;
}
我知道您可以通过使用类似于
的内容来检索光标的坐标不过,我目前正在尝试使用纯外部 javascript 文件,并附加如下事件:
element.onmousemove = getCursor
//or
element.onmousemove = function() {getCursor(parameters)}
我如何能够引用这些函数附加到的事件?
提前感谢您的帮助!
注意:我不使用 jQuery 或任何其他 javascript 库
更新
双倍更新!
阅读 Sime 的评论/回答
I'm currently trying to retrieve the coordinates of the cursor using
function getCursor(event) {
event.screenX;
event.screenY;
}
I know you can reference this event by using something similar to
<div onmousemove="getCursor(event)"></div>
However I am currently trying to use a purely external javascript file and am attaching events like so:
element.onmousemove = getCursor
//or
element.onmousemove = function() {getCursor(parameters)}
How would I be able to reference the event that these functions are attached to?
Thank you in advance for any help!
note: I do not use jQuery or any other javascript library
Update
MDC nvm! figured it out. You actually don't have to pass the param at all. element.onmousemove = getCursor
works great as long as you have function getCursor(event) {}
. Sorry bout that >_<.
Double Update!
Read Sime's comment/answer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
开始吧:
事件对象作为第一个参数自动传递到事件处理函数中。 Internet Explorer 8 及更低版本除外 -
e = e || window.event;
也将使其在这些版本的 IE 中工作。现场演示: http://jsfiddle.net/simevidas/DteK8/
Here you go:
The event object is passed as the first argument into the event handler function automatically. The exception is Internet Explorer 8 and below -
e = e || window.event;
will make it work in those versions of IE too.Live demo: http://jsfiddle.net/simevidas/DteK8/