简体   繁体   English

Internet Explorer中的鼠标坐标

[英]Mouse coordinates in Internet Explorer

I have a map for my game, I have a script that on a click displays an alert of the mouse coordinates on the map. 我有自己的游戏地图,我有一个脚本,单击该脚本可在地图上显示鼠标坐标的警报。

The map scale is 1 map unit to 2.5 pixels and the map starts at -600, 600 and goes down to 600, 1700. Thus I can't simply throw out the pixels of the mouse. 地图比例尺是1个地图单位为2.5像素,地图从-600,600开始,然后下降到600,1700。因此,我不能简单地抛出鼠标的像素。

I got it working (and was pretty happy about it) but alas IE (6) has issues. 我让它工作了(对此感到非常高兴),但是可惜IE(6)有问题。 I have narrowed it down to IE not correctly getting the scroll parameters. 我将其范围缩小到IE无法正确获取滚动参数。

Here is the relevant code that is glitching but the full code is located at http://woarl.com/map/ieMap.html 以下是出现故障的相关代码,但完整代码位于http://woarl.com/map/ieMap.html

tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;

Thanks for any help 谢谢你的帮助

Try: 尝试:

tempX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
tempY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop);

Checked your page, and the DOCTYPE is putting IE in standards mode, so the scrollXXX properties you want are actually in document.documentElement , not document.body . 检查了您的页面,DOCTYPE将IE置于标准模式,因此所需的scrollXXX属性实际上位于document.documentElement ,而不是document.body

Mouse coordinate locations are horrible, due to the specs not noting whether they ought to be relative to the document or the viewpane, amongst other things. 鼠标坐标的位置非常糟糕,这是因为规范特别指出了它们应该相对于文档还是相对于视窗。 There's a good description of the problem, as well as an example of script that should work across all browsers, at the bottom of http://www.quirksmode.org/js/events_properties.html . http://www.quirksmode.org/js/events_properties.html的底部,有一个很好的问题描述,以及一个适用于所有浏览器的脚本示例。

In particular it looks like you need to add document.documentElement.scroll(Left|Top) as well as the event and document.body parameters. 特别是看起来您需要添加document.documentElement.scroll(Left|Top)以及event和document.body参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript 中资源管理器的鼠标坐标 - Mouse coordinates for Explorer in Javascript 在Internet Explorer中移动鼠标后显示的图标 - Icon shown after mouse movement in Internet Explorer 在Internet Explorer 8中无法将鼠标事件附加到窗口对象上 - Attaching mouse events at the window object does not work in Internet Explorer 8 单击鼠标时html按钮的更改(切换)图像(在Internet Explorer中) - Change(toggle) image of a html button on mouse click (in Internet Explorer) 如何使用javascript为Internet Explorer获取鼠标指针位置? - How to get mouse pointer position using javascript for internet explorer? 鼠标坐标到等距坐标 - mouse coordinates to isometric coordinates 当执行单击+拖动鼠标操作时,Internet Explorer会冻结。 如何找出原因? - Internet Explorer freezes when a click + drag mouse action is performed. How to detect the cause of this? 单击Shift +鼠标左键单击时Internet Explorer浏览器出现问题,文本自动突出显示 - Internet Explorer browser issue while click shift + mouse-left-click , the text automatically get highlighted ArcGIS JavaScript API 3.9 - 鼠标拖动事件在 Internet Explorer 11 中不起作用 - ArcGIS JavaScript API 3.9 - mouse-drag events don´t work in Internet Explorer 11 Cufon Internet Explorer延迟 - Cufon delay in Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM