admin管理员组文章数量:1430077
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.
I got it working (and was pretty happy about it) but alas IE (6) has issues. I have narrowed it down to IE not correctly getting the scroll parameters.
Here is the relevant code that is glitching but the full code is located at .html
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
Thanks for any help
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.
I got it working (and was pretty happy about it) but alas IE (6) has issues. I have narrowed it down to IE not correctly getting the scroll parameters.
Here is the relevant code that is glitching but the full code is located at http://woarl./map/ieMap.html
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
Thanks for any help
Share Improve this question asked Jan 14, 2009 at 15:35 TeifionTeifion 111k76 gold badges164 silver badges196 bronze badges 1- How to make it so that IE doesn't go wrong :P – Teifion Commented Jan 14, 2009 at 16:27
2 Answers
Reset to default 4Try:
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
.
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/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.
本文标签: javascriptMouse coordinates in Internet ExplorerStack Overflow
版权声明:本文标题:javascript - Mouse coordinates in Internet Explorer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745504128a2661166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论