0

我在我的 ReactJS 项目中使用 malihu-custom-scrollbar-plugin,我可以通过编辑 node_modules 中的 css 来自定义滚动条,在 npm install 之后出现的问题 node_modules 中的所有更改都将消失,我需要一种方法来编辑滚动条拖动器和滚动条轨道的大小、颜色。还有向上和向下按钮,在 src 文件中而不是在节点模块中

这是我用于 malihu-custom-scrollbar-plugin 的代码:

import Box from '@mui/material/Box'
import $ from 'jquery';
import 'malihu-custom-scrollbar-plugin';
import 'malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css';
require('jquery-mousewheel');

const ListComponent = () => {



React.useEffect(()=>{
    $('.scroll').mCustomScrollbar({
        scrollButtons:{enable:true},
        theme:"rounded-dots-dark",
        scrollInertia:500
      });
},[])

 return (             
            <Box style={{overflowY: "hidden",
            height: "300px"}} className='scroll'>
            <p> A long lines of text</p>
            </Box>
)
}
4

1 回答 1

0

我找到的解决方案是覆盖malihu-custom-scrollbar-plugin中的css,使用元素检查(F5)我能够获得我想要自定义的html div,然后在我的App.css添加!重要来覆盖它:

.mCS-rounded-dark-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{
  background-color: red!important; //change the color of the dragger bar
  width: 20px!important; // change the width of the dragger bar
  height: 20px!important; //// change the height of the dragger bar
}
于 2021-12-09T15:06:04.133 回答