Skip to content

How to temporarily stop the scroll (Modal case) #361

Answered by idiotWu
HectorLS asked this question in FAQ
Discussion options

You must be logged in to vote

You can use plugin system to do this:

import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar';

class ModalPlugin extends ScrollbarPlugin {
  static pluginName = 'modal';

  static defaultOptions = {
    open: false,
  };

  transformDelta(delta) {
    return this.options.open ? { x: 0, y: 0 } : delta;
  }
}

Scrollbar.use(ModalPlugin, /* OverscrollPlugin */);

// usage
const scrollbar = Scrollbar.init(elem);

onModalOpen  -> scrollbar.updatePluginOptions('modal', { open: true });
onModalClose -> scrollbar.updatePluginOptions('modal', { open: false });

Replies: 13 comments 17 replies

Comment options

You must be logged in to vote
12 replies
@Minozzzi
Comment options

@Minozzzi
Comment options

@idiotWu
Comment options

@Minozzzi
Comment options

@Minozzzi
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
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@robizzt
Comment options

Comment options

You must be logged in to vote
1 reply
@robizzt
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@dngraphisme
Comment options

@idiotWu
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@anku598
Comment options

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
Converted from issue

This discussion was converted from issue #119 on June 10, 2021 17:08.