所以,我一直在试图让一个很好的jQuery的方式找到客户的滚动条的宽度。我想我已经在我的小提琴中找到了它,但显然增加了一个滚动条并没有改变孩子宽度的任何东西。即使在开发工具(chrome,FF)中,宽度也有所下降。
function scrollbarWidth() {
var div = $('<div class="outer"><div class="inner"></div>');
$('body').append(div);
var w1 = $(".inner").width();
$(".test-text span:first").text(w1);
console.log(w1);
$(".test-div").css('overflow-y', 'scroll');
var w2 = $(".inner").width();
$(".test-text span:last").text(w2);
console.log(w2);
}
scrollbarWidth();
使用innerWidth
没有什么区别。
这是怎么可能的,什么是解决方案?
看起来你正在试图做的[**这**](http://jsfiddle.net/adeneo/j9SkE/2/) – adeneo
是的,但只jQuery,而不是纯JS。 –
为什么你更喜欢纯js的jQuery? – adeneo