【问题标题】:How to customize malihu-custom-scrollbar-plugin in ReactJS?如何在 ReactJS 中自定义 malihu-custom-scrollbar-plugin?
【发布时间】:2022-01-13 07:33:01
【问题描述】:

我在我的 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>
)
}

【问题讨论】:

    标签: jquery css reactjs scrollbar mcustomscrollbar


    【解决方案1】:

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

    .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
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 2015-10-03
      • 1970-01-01
      • 2016-02-26
      • 2021-12-18
      • 2014-08-01
      • 2016-06-05
      • 1970-01-01
      • 2012-12-02
      相关资源
      最近更新 更多