我有代码在浏览器滚动时获取 x-y 坐标:
left1 = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
top1 = window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
这在 IE7 中有效,但在 Mozilla Firefox 3.5.19 中无效。如何让它在 Firefox 中运行?
最佳答案
以下 JS 在 IE 8 和 firefox 3.6.17 中工作
function getScrollingPosition()
{
var position = [0, 0];
if (typeof window.pageYOffset != 'undefined')
{
position = [
window.pageXOffset,
window.pageYOffset
];
}
else if (typeof document.documentElement.scrollTop
!= 'undefined' && document.documentElement.scrollTop > 0)
{
position = [
document.documentElement.scrollLeft,
document.documentElement.scrollTop
];
}
else if (typeof document.body.scrollTop != 'undefined')
{
position = [
document.body.scrollLeft,
document.body.scrollTop
];
}
return position;
}
这篇文章也可能有所帮助。 http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html
关于javascript - 在javascript中滚动单击鼠标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6307307/