使用 jQuery 和 CutyCapt 进行浏览器相对定位
我一直在使用 CutyCapt 截取多个网页的屏幕截图,并取得了巨大成功。我现在的挑战是在那些代表用户点击位置的屏幕截图上画一些点。
CutyCapt 在拍摄屏幕截图之前会经历将网页大小调整为滚动宽度的过程。这非常有用,因为您只能获得内容,而不能获得太多(如果有的话)页面背景。
我的挑战是尝试将用户的鼠标 X 坐标映射到屏幕截图。显然,用户具有不同的屏幕分辨率,并且他们的浏览器窗口打开为不同的尺寸。下图显示了 3 个具有相同徽标的示例。例如,假设徽标距离“内容”区域(红色)左边缘 10 个像素。
在每种情况下,对于任何分辨率,我都需要一个 JavaScript 例程来计算徽标的 X 坐标为 10。同样,挑战(我认为)是不同的分辨率。在居中对齐的示例中,徽标的位置(从浏览器的左边缘(黑色)开始测量)随着浏览器大小的变化而变化。左对齐的示例应该很简单,因为徽标不会随着屏幕大小的调整而移动。
有人能想出一种方法来计算页面的可滚动宽度吗?换句话说,我正在寻找一个 JavaScript 解决方案来计算水平滚动条出现之前浏览器窗口的最小宽度。我需要在不知道任何元素 ID 或类名的情况下执行此操作。
感谢您的帮助!
I've been using CutyCapt to take screen shots of several web pages with great success. My challenge now is to paint a few dots on those screen shots that represent where a user clicked.
CutyCapt goes through a process of resizing the web page to the scroll width before taking a screen shot. That's extremely useful because you only get content and not much (if any) of the page's background.
My challenge is trying to map a user's mouse X coordinates to the screen shot. Obviously users have different screen resolutions and have their browser window open to different sizes. The image below shows 3 examples with the same logo. Assume, for example, that the logo is 10 pixels to the left edge of the "content" area (in red).
In each of these cases, and for any resolution, I need a JavaScript routine that will calculate that the logo's X coordinate is 10. Again, the challenge (I think) is differing resolutions. In the center-aligned examples, the logo's position, as measured from the left edge of the browser (in black), differs with changing browser size. The left-aligned example should be simple as the logo never moves as the screen resizes.
Can anyone think of a way to calculate the scrollable width of a page? In other words, I'm looking for a JavaScript solution to calculate the minimum width of the browser window before a horizontal scroll bar shows up. And I need to do this without first knowing any element IDs or class names.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得元素所需的总空间:
您必须将其添加到元素的位置:
所以:
希望这有帮助:-??
You can get the total space an element needs:
You have to add that to the position of the element:
So:
Hope this helps :-??
如果我理解正确的话,那么这应该对你有用!
它应该返回用户浏览器窗口的宽度。
希望这有帮助!
If I understand you correctly, then this is what should work for you!
It should return the width of the persons browser window.
Hope this helps!