gpt4 book ai didi

html - 隐藏滚动条,但仍然可以滚动

转载 作者:bug小助手 更新时间:2023-10-28 10:52:50 31 4
gpt4 key购买 nike

我希望能够滚动整个页面,但不显示滚动条。

在谷歌浏览器中是:

::-webkit-scrollbar {
display: none;
}

但 Mozilla Firefox 和 Internet Explorer 似乎不能那样工作。

我也在 CSS 中试过这个:

overflow: hidden;

确实隐藏了滚动条,但我不能再滚动了。

有没有一种方法可以在移除滚动条的同时还能滚动整个页面?

请只使用 CSS 或 HTML。

最佳答案

只是一个运行良好的测试。

#parent{
width: 100%;
height: 100%;
overflow: hidden;
}

#child{
width: 100%;
height: 100%;
overflow-y: scroll;
padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
box-sizing: content-box; /* So the width will be 100% + 17px */
}

Working Fiddle

JavaScript:

由于不同浏览器的滚动条宽度不同,最好用JavaScript来处理。如果您执行 Element.offsetWidth - Element.clientWidth,则会显示确切的滚动条宽度。

JavaScript Working Fiddle

或者

使用position:absolute,

#parent{
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}

#child{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: -17px; /* Increase/Decrease this value for cross-browser compatibility */
overflow-y: scroll;
}

Working Fiddle

JavaScript Working Fiddle

信息:

基于这个答案,我创建了一个 simple scroll plugin .

关于html - 隐藏滚动条,但仍然可以滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16670931/

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