使用 jQuery 和 CutyCapt 进行浏览器相对定位

发布于 2024-10-10 08:11:21 字数 620 浏览 0 评论 0原文

我一直在使用 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!

alt text

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

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

发布评论

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

评论(2

爱她像谁 2024-10-17 08:11:21

您可以获得元素所需的总空间:

function getWidth(x){
    var totalWidth = x.width();
    totalWidth += parseInt(x.css("padding-left"), 10) + parseInt(x.css("padding-right"), 10); //Total Padding Width
    totalWidth += parseInt(x.css("margin-left"), 10) + parseInt(x.css("margin-right"), 10); //Total Margin Width
    totalWidth += parseInt(x.css("borderLeftWidth"), 10) + parseInt(x.css("borderRightWidth"), 10); //Total Border Width 
    return totalWidth;

 }

您必须将其添加到元素的位置:

$('#yourlogo').offset().left;

所以:

var window-width =  $('#yourlogo').offset().left + getWidth($('#yourlogo'));

希望这有帮助:-??

You can get the total space an element needs:

function getWidth(x){
    var totalWidth = x.width();
    totalWidth += parseInt(x.css("padding-left"), 10) + parseInt(x.css("padding-right"), 10); //Total Padding Width
    totalWidth += parseInt(x.css("margin-left"), 10) + parseInt(x.css("margin-right"), 10); //Total Margin Width
    totalWidth += parseInt(x.css("borderLeftWidth"), 10) + parseInt(x.css("borderRightWidth"), 10); //Total Border Width 
    return totalWidth;

 }

You have to add that to the position of the element:

$('#yourlogo').offset().left;

So:

var window-width =  $('#yourlogo').offset().left + getWidth($('#yourlogo'));

Hope this helps :-??

深居我梦 2024-10-17 08:11:21

如果我理解正确的话,那么这应该对你有用!

var browserWidth=$(window).width();   // returns width of browser viewport

它应该返回用户浏览器窗口的宽度。

希望这有帮助!

If I understand you correctly, then this is what should work for you!

var browserWidth=$(window).width();   // returns width of browser viewport

It should return the width of the persons browser window.

Hope this helps!

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