【问题标题】:nicescroll.js - how to disable vertical scrollbar?nicescroll.js - 如何禁用垂直滚动条?
【发布时间】:2025-12-28 10:25:06
【问题描述】:

我用jquery-nicescroll:

$(this.refs.container).niceScroll({
  cursorcolor: '#f16221',
  cursorwidth: '14',
  cursorminheight: '64',
  scrollspeed: '50',
  autohidemode: 'false',
  overflowy: 'false'
})

目前它有两个滚动条:垂直和水平。我需要隐藏/禁用垂直滚动条,但没有找到解决方案。我尝试添加overflowy: 'false',但没有成功。 horizrailenabled: false 效果很好,但没有垂直选项。

类似的问题: Disable Vertical Scroll in niceScroll Js

如何使用nicescroll隐藏垂直滚动条?

【问题讨论】:

  • 你试过overflowy: false,即布尔值而不是字符串?
  • 是的,尝试布尔值 false。我在 React 组件中使用它。还尝试了“隐藏”
  • 您是否尝试过通过 css 禁用元素上的垂直溢出?
  • 我可以用#ascrail2000 { display: none !important; }

标签: javascript html css reactjs nicescroll


【解决方案1】:

我建议添加以下 jQuery 代码以获得完整的解决方案,以禁用和隐藏垂直滚动条:

var nice = 
    $(this.refs.container).niceScroll({
        cursorcolor: '#f16221',
        cursorwidth: '14',
        cursorminheight: '64', 
        scrollspeed: '50',
        autohidemode: 'false',
        overflowy: 'false'
    });

var _super = nice.getContentSize;

nice.getContentSize = function () {
    var page = _super.call(nice);
    page.h = nice.win.height();
    return page;
}

$('.nicescroll-rails.nicescroll-rails-vr').remove();

(在https://code.google.com/archive/p/jquery-nicescroll/issues/27 部分提及)

【讨论】: