【发布时间】:2022-10-08 17:32:27
【问题描述】:
我正在开发一个滚动条,它可能会显示不同事物的子类别。例如鞋子、衣服等。当您将鼠标悬停在箭头上时,有没有一种方法可以让滚动条自行移动(从左到右,反之亦然,具体取决于箭头的方向)。如果可能的话,我想使用 Vanilla JS
.collections-nav {
white-space: nowrap;
overflow-x: auto;
display: flex;
gap: 15px;
padding-left: 0rem;
margin-top: 2rem;
padding-bottom: 1.5rem;
}
.collections-nav li {
background: #FFF;
border-radius: 50px;
padding: 7px 20px;
font-size: 0.75rem;
box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%);
font-family: 'Open-Bold', sans-serif;
color: #0A2540;
list-style-type: none;
cursor: pointer;
}
.collections-nav li:hover {
background: #0a2540;
opacity: 0.95;
transition: 0.3s ease-in-out;
color: #FFF;
}
.collections-nav .active {
background: #0A2540;
color: #FFF;
}
.collections-nav::-webkit-scrollbar {
height: 7px !important;
/* width of the entire scrollbar */
}
.collections-nav::-webkit-scrollbar-track {
background: #F6F9FC;
/* color of the tracking area */
border-radius: 10px;
}
.collections-nav::-webkit-scrollbar-thumb {
background-color: #0A2540;
/* color of the scroll thumb */
border-radius: 10px;
}
<div class="collections">
<ul class="collections-nav nav-tabs pb-3">
<li class="active">Home</li>
<li>Profile</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
</div>
【问题讨论】:
-
它让我了解了它的外观/工作方式,但是它似乎没有任何纯 js 解决方案,因为我不想将整个库添加到我的项目中,因为我也从未使用过jquery 所以我不太明白
标签: javascript html css