根据文档(https://github.com/malte-wessel/react-custom-scrollbars/blob/master/docs/customization.md)
<Scrollbars
renderTrackHorizontal={props => <div {...props} className="track-horizontal"/>}
renderTrackVertical={props => <div {...props} className="track-vertical"/>}
renderThumbHorizontal={props => <div {...props} className="thumb-horizontal"/>}
renderThumbVertical={props => <div {...props} className="thumb-vertical"/>}
renderView={props => <div {...props} className="view"/>}>
<div>
content here
</div>
</Scrollbars>
然后应用波纹管CSS,让基础工作。并根据需要进行调整。
(在 SCSS 中)
.track-vertical {
top: 2px;
bottom: 2px;
right: 2px;
border-radius: 3px;
background: rgba(255, 255, 255, 0.111);
.thumb-vertical {
position: relative;
display: block;
width: 100%;
cursor: pointer;
border-radius: inherit;
background-color: rgba(123, 154, 255, 0.418); // changed the color
}
}
.track-horizontal {
position: absolute;
height: 6px;
right: 2px;
bottom: 2px;
left: 2px;
border-radius: 3px;
.thumb-horizontal {
position: relative;
display: block;
height: 100%;
cursor: pointer;
border-radius: inherit;
background-color: rgba(125, 149, 255, 0.993); // changed the color
}
}
.view {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: scroll;
margin-right: -15px;
margin-bottom: -17px !important; // changed from -15px (default) to -17px (native scrollbar had a portion visible)
}
这是我们不手动渲染元素时默认应用的样式。传递的props将处理更新拇指的尺寸。
不知道是不是故意的 所以我们可以自定义我们想要的方式,而且我们不必在我们的 css 中使用 !important(看起来像那样!)。
对于.view元素。样式被传递,如果你想覆盖(因为我需要自己(边距:-17px,而不是 -15px))然后只是 css 规则。使用!重要。或者使用内联 css。
以上是SCSS。下面是编译好的css:
(在 CSS 中)
.track-vertical {
top: 2px;
bottom: 2px;
right: 2px;
border-radius: 3px;
background: rgba(255, 255, 255, 0.111);
}
.track-vertical .thumb-vertical {
position: relative;
display: block;
width: 100%;
cursor: pointer;
border-radius: inherit;
background-color: rgba(123, 154, 255, 0.418);
}
.track-horizontal {
position: absolute;
height: 6px;
right: 2px;
bottom: 2px;
left: 2px;
border-radius: 3px;
}
.track-horizontal .thumb-horizontal {
position: relative;
display: block;
height: 100%;
cursor: pointer;
border-radius: inherit;
background-color: rgba(125, 149, 255, 0.993);
}
.view {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: scroll;
margin-right: -15px;
margin-bottom: -17px !important;
}