JQuery的$(窗口)。宽度()不包括滚动条宽度? [英] Jquery $(window).width() excluding scrollbar width?

查看:1298
本文介绍了JQuery的$(窗口)。宽度()不包括滚动条宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用javascript设置很多css属性的页面,它使用$(window).width()来确定页面宽度。除此之外,它使用该方法将一些div宽度设置为页面的整个宽度。 A这样做是因为很多其他的计算都是在javascript中完成的。

无论如何,我正在切换到不同的导航风格,我设置了主体的溢出 - y被隐藏。不幸的是,既然滚动条已经消失了,我在页面的边上留下了一个可爱的白色条(在我试过的每个浏览器中),这正是滚动条的宽度。如果没有具体计算滚动条的宽度(可能会变得混乱),我怎么才能得到包括滚动条在内的完整浏览器的宽度?



谢谢!



编辑:这是一个操作问题的顺序,我当时是一个白痴。对不起!

解决方案

window.outerWidth



outerWidth属性设置或返回窗口的外部宽度,包括所有界面元素(如工具栏/滚动条)。

http://www.w3schools.com/jsref/prop_win_outerheight.asp


I've got a page that sets a lot of css properties using javascript and it uses $(window).width() to determine the page width. Among other things, it sets some div widths to be the full width of the page using that method. A It's done this way because a lot of the other calculations are done in javascript.

Anyway, I'm switching to a different navigation style and I set the body's overflow-y to be hidden. Unfortunately, now that the scrollbar has disappeared I'm left with a lovely white bar at the side of my page (in every browser I've tried) that is exactly the width of the scroll bar. Without specifically calculating the width of the scroll bar, which can get messy, how can I just get the width of the full browser including the scroll bar?

Thanks!

EDIT: It was an order of operations issue, I was being an idiot. Sorry!

解决方案

window.outerWidth

The outerWidth property sets or returns the outer width of a window, including all interface elements (like toolbars/scrollbars).

http://www.w3schools.com/jsref/prop_win_outerheight.asp

这篇关于JQuery的$(窗口)。宽度()不包括滚动条宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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