【发布时间】:2019-03-02 16:34:59
【问题描述】:
问题
滚动条是通过图像实现的。
我参考以下内容制作了这样的滚动条。
参考以下,现在滚动条变成了这个样子。
参考站:
I want to make knob of input range an image - StackOverflowJP(日文站对不起..)
Implement scrollbar-button - JSFiddle
- 指定
scrollbar的宽度和高度大小 -
scrollbar-button左/右一一 - 将
scrollbar定位在远离目标的位置
代码
▼ 除非是webkit 浏览器(例如 Chrome 等),否则可能无法正确显示
html {font-size: 62.5%;}
#thumb-wrap {
position: relative;
box-sizing: border-box;
width: 100%;
margin-bottom: 12.4rem;
overflow-x: scroll;
overflow-y: hidden;
writing-mode: bt-lr; /* IE */
-webkit-appearance: none;
}
#thumb-wrap::-webkit-scrollbar {
width: 33.2rem;
}
#thumb-wrap::-webkit-scrollbar-track {
-webkit-appearance: none;
width: 30.1rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080150.png");
}
#thumb-wrap::-webkit-scrollbar-thumb {
width: 1.5rem;
height: 1.3rem;
background: #fff;
border: 1px solid #000;
}
#thumb-wrap::-webkit-scrollbar-button {
width: 1.6rem;
height: 1.6rem;
}
#thumb-wrap::-webkit-scrollbar-button:start {
display: block;
}
#thumb-wrap::-webkit-scrollbar-button:horizontal:decrement {
width: 1.6rem;
height: 1.6rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080158.png") no-repeat center center;
}
#thumb-wrap::-webkit-scrollbar-button:end {
display: block;
}
#thumb-wrap::-webkit-scrollbar-button:horizontal:increment {
width: 1.6rem;
height: 1.6rem;
background: url("https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228080155.png") no-repeat center center;
}
#thumb-wrap ul {
width: 100%;
white-space: nowrap;
}
#thumb-wrap li {
display: inline-block;
}
#thumb-wrap li:first-child {
margin-left: 3rem;
}
#thumb-wrap li:last-child {
margin-right: 3rem;
}
#thumb-wrap li + li {
margin-left: 3rem;
}
<div id="thumb-wrap">
<ul>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075715.png" alt="あ=a" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075712.png" alt="い=b" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075710.png" alt="う=c" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075706.png" alt="え=d" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075704.png" alt="お=e" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075810.png" alt="か=f" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075807.png" alt="き=g" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075805.png" alt="く=h" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075802.png" alt="け=i" /></a>
</li>
<li>
<a href="#"><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/O/O2_milk/20190228/20190228075759.png" alt="こ=j" /></a>
</li>
</ul>
</div>
【问题讨论】:
-
滚动条通常按照浏览器的需要非常严格地显示。对于大多数浏览器,您无法在原生浏览器上进行太多修改。我的建议是用 css 完全隐藏它,然后他们用 JavaScript 实现一个自定义的。
-
@JensV 哦,JavaScript!至于JavaScript我是一个真正的初学者,我仍然觉得很难,所以如果我不能通过CSS来做我会尝试它。感谢您的建议! :)