处理滚动条和jquery .width()方法 [英] Dealing with scroll bars and jquery .width() method
问题描述
jQuery的 .width()
方法似乎不考虑滚动条。这对我是有问题的,因为我想设置一些孩子的宽度等于其父的宽度。我使用类似于以下的jQuery:
jQuery's .width()
method doesn't seem to account for scroll bars. This is problematic for me, since I'd like to set the width of some children to equal the width of their parent. I used jQuery similar to the following:
$('#contentDiv').width($('#containerDiv').width())
在此示例中, #contentDiv
是我想要定义的元素,我想设置它的宽度为 #containerDiv
,这是它的父元素。我的问题是,这切断了 #contentDiv
的一面,如这个小提琴所示。 / a>
In this example, #contentDiv
is the element I'd like to size, and I want to set it to have the width of #containerDiv
, which is its parent element. My problem is that this cuts off the side of #contentDiv
, as seen in this fiddle.
在我的实际代码中,我有几个元素,我用jQuery调整大小,所有这些都需要适应可滚动的div,所以只要设置css的 #contentDiv
到100%不是一个选项。在jQuery中处理div的滚动条宽度的最好方法是什么?
In my actual code, I have several elements that I'm sizing with jQuery, which all need to fit in the scrollable div, so just setting the css of #contentDiv
to 100% is not an option. What's the best way of dealing with scroll bar widths of divs in jQuery?
推荐答案
是这样:
http:// chris-spittles.co.uk/?p=531
jQuery是所有功能强大,但有时一个小破折号的原生JS是你需要的渲染像素完美的页...我希望你会发现这个解决方案有帮助!
jQuery is all powerful and everything but sometimes a small dash of native JS is all you need to render pixel perfect pages... I hope you will find this solution helpful!
这篇关于处理滚动条和jquery .width()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!