Skip to content

How to disable horizontal scolling #357

Answered by idiotWu
TobiasDonaubauer asked this question in FAQ
Discussion options

You must be logged in to vote

I would like to disable the horizontal scrolling

You can use this plugin to disable scrolling in a particular direction:

// see also: https://github.com/idiotWu/react-smooth-scrollbar/issues/15#issuecomment-335047892
import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar';

class DisableScrollPlugin extends ScrollbarPlugin {
  static pluginName = 'disableScroll';

  static defaultOptions = {
    direction: '',
  };

  transformDelta(delta) {
    if (this.options.direction) {
      delta[this.options.direction] = 0;
    }

    return { ...delta };
  }
}

// load the plugin
Scrollbar.use(DisableScrollPlugin);

// usage
Scrollbar.init(elem, {
  plugins: {
    disableScroll: {
      d…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@pszczesniak
Comment options

@idiotWu
Comment options

@pszczesniak
Comment options

@idiotWu
Comment options

Answer selected by idiotWu
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
FAQ Frequently Asked Questions
4 participants
Converted from issue

This discussion was converted from issue #206 on June 10, 2021 17:05.