$(document).width() 包括 ie8 中的滚动条

发布于 2024-09-30 04:25:39 字数 613 浏览 0 评论 0原文

我有以下网页:

一个高网页,只有垂直滚动条,没有水平滚动条。因此,文档和窗口具有相同的宽度。

当我向 IE8 询问 $(document).width() 时,它返回包括垂直滚动条的视口宽度。 FF 返回正确答案。

我不能为此使用 $('body') ,因为它返回与窗口对象相同的宽度(它以某种方式设置为 100%,因此当页面变小时它不起作用) 。

如何让IE8输出正确的值?提前致谢。

更新

我实际上对我的问题做了一些更多的测试。我发现当水平滚动条也变得可见时(因为窗口较小),IE8 确实获得了正确的大小。所以这让我的问题变得更加复杂,因为我无法设置一个丑陋的 if(IE8)-hack。

UPDATE2

问题出在我的 CSS 和 jQuery 上。 实际案例似乎有问题: 我的 css 说:

body
{
    overflow-y:scroll;
}

IE8 不将其视为正文的一部分,但 IE7 会这样做。如何解决这个问题?调用 jQuery 进行修复?

I have the following webpage:

A tall webpage with only a vertical scrollbar and no horizontal scrollbar. The document and window therefore have the same width.

When I ask IE8 for $(document).width(), it returns the viewport width including the vertical scrollbar. FF returns the right answer.

I cannot use $('body') for this, because it returns the same width as the window object (it is set to 100% somehow, so it doesn't work when the page gets smaller).

How can I make IE8 output the right value? Thanks in advance.

UPDATE

I actually did some more testing to my problem. and I found that when the horizontal scrollbar becomes visible as well (because of a smaller window), IE8 DOES get the right size. So this makes my problem even more complicated because I can't set an ugly if(IE8)-hack.

UPDATE2

The problem lies in my CSS and jQuery.
The actual case seems to be the problem:
My css says:

body
{
    overflow-y:scroll;
}

IE8 doesn't count this as part of the body, but IE7 does. How to fix this? Call jQuery for a fix?

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

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

发布评论

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

评论(1

负佳期 2024-10-07 04:25:39

我把这个问题交给了 jQuery 团队: http://bugs.jquery.com/ticket/8048

他们不认为这是一个错误。他们的建议是使用 $('body').width()。这确实适合我。

我还是觉得奇怪,IE8中的body调整到了滚动条,但是$(document).width()保持不变。我使用这个 jsFiddle 进行测试。它会导致同样的故障,但 jQuery 认为没关系,因为 W3C 没有对此说什么......或者类似的东西。

I put this problem to the jQuery crew: http://bugs.jquery.com/ticket/8048.

They don't think it's a bug. Their advice is to use $('body').width(). And this does indeed the job for me.

I still find it strange that the body in IE8 is adjusted to the scrollbar, but the $(document).width() stays the same. I used this jsFiddle for testing. It results in the same glitch, but jQuery thinks it's ok, because W3C doesn't say anything about it... Or something like that.

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