react实现滚动条的方法:1、使用“render() {const translatedistancepercentage...}”方式设置滚动条滚动百分比;2、通过“.scrollbar {width: 362px;...}”设置滚动条宽度;3、设置样式为“left: -362px;top: 0px;position: absolute;”即可。

本教程操作环境:windows10系统、react18版、dell g3电脑。
react怎么实现滚动条?
react-实现滚动条
一、实现效果

二、实现代码
jsx
render() {
const translatedistancepercentage = '33.33333333333333'; // 滚动条滚动百分比
console.log('滚动条滚动百分比' translatedistancepercentage);
return (
// 滚动条
)
}less
.scrollbar {
/** 滚动条宽度 */
width: 362px;
height: 12px;
left: 0px;
top: 36px;
position: absolute;
opacity: 0.7;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
.scrollbarhousing {
width: 100%;
height: 100%;
left: 0px;
top: 0px;
position: absolute;
border-radius: 60px;
/** 下面这个很关键喔 */
overflow: hidden;
.insidescrollbar {
width: 100%;
height: 100%;
/** 让滚动条内里一来就先位于滚动条外最左侧 */
left: -362px;
top: 0px;
position: absolute;
border-radius: 60px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
}
}下图圈出来了一些关键样式,颜色相同滴前后呼应喔~

花銭约芐