Firefox:获取视口左上角的鼠标坐标 [英] Firefox: Get mouse coordinates of top-left corner of viewport

查看:192
本文介绍了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:获取视口左上角的鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆