The following sections describe the major changes from 7.x to 8.x.
- Plugin System
- Standalone overscroll plugin
- Deprecated Options
- Imcompatible Properties
- Deprecated Methods
- Imcompatible Methods
smooth-scrollbar.css
has been removed from 8.x, you just need to import the main js module/bundle 🙌.
See Plugin System for details;
Overscroll effect is no longer bundle with main package. You need to import it manually:
import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll';
Scrollbar.use(OverscrollPlugin);
Scrollbar.init(elem, {
plugins: {
overscroll: options | false,
},
});
OR
<script src="dist/smooth-scrollbar.js"></script>
<script src="dist/plugins/overscroll.js"></script>
<script>
var Scrollbar = window.Scrollbar;
Scrollbar.use(window.OverscrollPlugin)
Scrollbar.init(elem, {
plugins: {
overscroll: options | false,
},
});
</script>
The following options have been removed from 8.x.
Reason: can be implemented with ScrollPlugin
:
// 7.x speed scale
options.speed = 10;
// equivalent in 8.x
class ScalePlugin {
static pluginName = 'scale';
static defaultOptions = {
speed: 1,
};
transformDelta(delta) {
const { speed } = this.options;
return {
x: delta.x * speed,
y: delta.y * speed,
};
}
}
Scrollbar.use(ScalePlugin);
Scrollbar.init(elem, {
plugins: {
scale: {
speed: 10,
},
},
});
Reason: scrolling listeners will always be invoked synchronously.
// 7.x asynchronous listener:
options.syncCallbacks = false;
// equivalent in 8.x
scrollbar.addListener(() => {
requestAnimationFrame(() => {
// do something
});
});
Reason: use overscroll plugin.
Removed in 8.x.
Reason: can be implemented with ScrollbarPlugin
.
Reason: use scrollbar.setMomentum(0, 0)
.
Reason: could be implemented via plugin system:
import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar';
class FilterEventPlugin extends ScrollbarPlugin {
static pluginName = 'filterEvent';
static defaultOptions = {
blacklist: [],
};
transformDelta(delta, fromEvent) {
if (this.shouldBlockEvent(fromEvent)) {
return { x: 0, y: 0 };
}
return delta;
}
shouldBlockEvent(fromEvent) {
return this.options.blacklist.some(rule => fromEvent.type.match(rule));
}
}
Scrollbar.use(FilterEventPlugin);
const scrollbar = Scrollbar.init(elem);
// block events
// 8.0.x
scrollbar.options.plugins.filterEvent.blacklist = [/wheel/, /touch/];
// 8.1.x
scrollbar.updatePluginOptions('filterEvent', {
blacklist: [/wheel/, /touch/],
});
7.x: scrollbar.setPosition(x, y, withoutCallbacks)
8.x: scrollbar.setPosition(x, y, options)
// 7.x
scrollbar.setPosition(0, 0, true);
// equivalent in 8.x
scrollbar.setPosition(0, 0, {
withoutCallbacks: true,
});
7.x: scrollbar.scrollTo(x, y, duration, callback)
8.x: scrollbar.scrollTo(x, y, duration, options)
// 7.x
scrollbar.scrollTo(0, 0, 300, cb);
// equivalent in 8.x
scrollbar.scrollTo(0, 0, 300, {
callback: cb,
});