Firefox:获取视口左上角的鼠标坐标

编程入门 行业动态 更新时间:2024-10-24 12:32:50
本文介绍了Firefox:获取视口左上角的鼠标坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 每个人都有美好的一天。

我正在使用Firefox扩展,我想从鼠标光标的某个偏移处弹出一个工具提示。但是,当偏移量超出视口时,问题就来了。它被显示,但用户将不得不在那里滚动。我希望通过在当前视口中移动工具提示来增强它。

然而,出现了一个问题,因为唯一的线索我必须在文档中的位置是鼠标位置。一个部分的解决办法是计算出多少移动我的工具提示找出当前的鼠标坐标+工具提示宽度/高度,看看它是否会超过window.innerHeight或window.innerWidth。

然而,我意识到如果它是一个非常长的文档,并且用户向下滚动一点点,那么鼠标坐标将会有一个非常大的y值。因此,我不能单靠window.innerHeight来看看我是否还在视口之内。任何人都找到了一种方法来查找视口左上角的鼠标坐标,如果用户滚动了很多?

预先感谢您! =

解决方案

更具体地说在你的情况下, document.body.scrollTop 。

然而,这是相当特定的IE浏览器,这是大多数FireFox扩展的目的。 ;-)还有一些DTD依赖关系可以启动。

这看起来像你想要的:确定浏览器尺寸和文档滚动偏移量

Good day everyone.

I am working on a Firefox extension, and I want to pop up a tooltip at a certain offset from the mouse cursor. However, the problem comes when this offset is out of the viewport. It gets displayed but the user will have to scroll over there. I hope to enhance this by moving the tooltip pop-up within the current viewport.

However, a problem arises because the only clue I have to where I am in the document is the mouse-position. A partial solution would be to calculate how much to move my tooltip by finding out if the current mouse coordinate + the tooltip width/height and see if it will exceed window.innerHeight or window.innerWidth.

However, I come to realize that if it was a very long document and the user scrolled down a fair bit, the mouse coordinate would have a very large y value. Therefore, I can't rely solely on window.innerHeight to see if I am still within the viewport. Anyone found a way to find out the mouse coordinate of the top left corner in the viewport if the user has scrolled down a lot?

Thank you in advance! =)

解决方案

More specifically in your case, document.body.scrollTop.

However, that's pretty IE-specific, which defeats the purpose of most FireFox extensions. ;-) There are also some DTD dependencies to boot.

This looks like what you want: Determining browser dimensions and document scroll offsets

更多推荐

Firefox:获取视口左上角的鼠标坐标

本文发布于:2023-11-09 06:04:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   左上角   坐标   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!