您的位置:首页 > Web前端 > JavaScript

(javascript) 获取鼠标事件发生坐标的问题

2007-08-11 17:52 405 查看
软件环境ie 6,vs2005,今天在弄一个需要获取事件位置的坐标的时候发现网上很多人用的document.body.scrollTop一直都为0,百思不得其解,于是上网搜索看看该怎么使用scrollTop才对,居然很幸运的被我发现一个网页上面(http://forums.digitalpoint.com/showthread.php?t=11965)有人给出了答案,说是ie6下面如果要使用scrollTop得用document.documentElement.scrollTop才能获取得到滑动条滑动的偏移量,并给出了代码来解决兼容其他浏览器的问题

if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
else if (document.documentElement && document.documentElement.scrollTop)
// IE6 +4.01 and user has scrolled
else if (document.body && document.body.scrollTop)
// IE5 or DTD 3.2

经过在ie上面简单测试(ie6)该答案是正确的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: