jquery - html ::-webkit-scrollbar 未通过 jquery 应用
问题描述
我可以通过以下方式隐藏 Chrome 中的滚动条:
# app.css loaded in <head>
html ::-webkit-scrollbar {
display: none;
}
现在我想手动隐藏滚动条,所以我尝试使用 jQuery 运行以下命令:
$("html ::-webkit-scrollbar").css("display", "none")
但是,滚动条在滚动期间保持可见。
如何手动隐藏/显示滚动条?
解决方案
根据这个答案:webkit scrollbar using jQuery.css() method你不能使用 JQuery 处理伪元素,但你可以使用一个类来“破解”它:
$('html').addClass('hide-scrolling')
.hide-scrolling::-webkit-scrollbar {
width: 30px;
}
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
推荐阅读
- algorithm - 当必须始终包含一条或多条边时,完整无向图中的哈密顿回路总数是多少?
- python - AttributeError:模块“google.cloud.vision”没有属性“客户端”
- html - 在主屏幕上为书签设置 Apple Touch 图标的标题
- android - 选项卡未添加到页面的问题
- ios - 在其 parentView 中正确居中 uiviews
- python-3.x - 张量流线性分类器预测函数
- arrays - 在 Fortran 数组中查找第一个和最后一个正值
- python - mnist 训练和测试精度仅为 0.49
- r - 如何将列中的每个数据分别转换为新表中的新列
- python - 无法在 jupyter notebook 中导入包