在我的頁面中,我希望檢測頁面是否具有垂直滾動條,如果需要,則需要檢測滾動條的寬度,以便減少我的身體的寬度,從而防止我的邊欄從查看非滾動頁面到滾動頁面的位置發生變化。 我有以下的jQuery/Javascript代碼:檢測垂直滾動和滾動條寬度並將寬度更改應用於主體
$(document).ready(function() {
var parent, child, width;
if (width === undefined) {
parent = $('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body');
child = parent.children();
width = child.innerWidth() - child.height(99).innerWidth();
parent.remove();
}
if ($("body").height() > $(window).height()) {
//change width of body here
}
});
不幸的是,這個代碼不爲我工作。有人可以讓我知道我要去哪裏嗎?