Firefox:获取视口的实际屏幕位置

发布于 2024-07-18 02:50:00 字数 167 浏览 5 评论 0原文

对于firefox来说,是否有办法确定“视口”(即客户区域)的左上角位置? 我知道高度/宽度可以通过 window.innerHeight 和 window.innerWidth 获得。 但我还需要知道“innerTop”和“innerLeft”(它们不存在)。

谢谢,

罗布

For firefox is there anyway to determine the TopLeft location of the "viewport" (ie the client area)? I know the height/width is available via window.innerHeight and window.innerWidth. But I also need to know "innerTop" and "innerLeft" (which don't exist).

Thanks,

Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

宛菡 2024-07-25 02:50:00

如果能获取到鼠标事件,可以查看其 event.screenX /screenY 属性并减去 event.clientX/clientY 属性。 这甚至是跨浏览器兼容的(DOM 级别 2 事件)。

If you can get a mouse event, you can look at its event.screenX/screenY properties and subtract the event.clientX/clientY properties. This is even cross-browser compatible (DOM Level 2 Events).

梦冥 2024-07-25 02:50:00
  • window.innerHeight - 的高度文档区域。
  • window.outerHeight - 整个窗口的高度。

您可以将一个与另一个相减,并得到文档区域距窗口顶部的距离,加上状态栏的高度。

  • window.innerHeight - The height of the document area.
  • window.outerHeight - The height of the entire window.

You could subtract one from another, and get the distance of the document area from the top of the window, plus the height of the status bar.

最笨的告白 2024-07-25 02:50:00

试试这个:

document.documentElement.getBoundingClientRect()

这个函数的结果将有一个 left 和一个 top 属性,这将为您提供所需的内容。

注意:此函数是在 Fx3 中实现的,因此对于旧版本,您需要 DOM 遍历 offsetParent 迭代。

Try this:

document.documentElement.getBoundingClientRect()

The result of this function will have a left and a top property which will give you what you need.

Note: This function is implemented in Fx3 so you'll need the DOM-traversing offsetParent iteration for older versions.

剑心龙吟 2024-07-25 02:50:00

这似乎也给出了从文档顶部到视口的偏移量:

window.pageYOffset

This seems to give the offset from the top of the document to the viewport too:

window.pageYOffset

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文