[英]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.