gpt4 book ai didi

javascript - 如何获取浏览器的滚动条大小?

转载 作者:IT老高 更新时间:2023-10-28 13:17:22 25 4
gpt4 key购买 nike

如何在 JavaScript 中确定水平滚动条的高度或垂直滚动​​条的宽度?

最佳答案

来自 Alexandre Gomes Blog我还没有尝试过。让我知道它是否适合你。

function getScrollBarWidth () {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";

var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);

document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth;

document.body.removeChild (outer);

return (w1 - w2);
};

关于javascript - 如何获取浏览器的滚动条大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/986937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com