Skip to content

Instantly share code, notes, and snippets.

@jesperlandberg
Created January 29, 2018 09:34
Show Gist options
  • Save jesperlandberg/4add9392bcc476884685f34002edfbe4 to your computer and use it in GitHub Desktop.
Save jesperlandberg/4add9392bcc476884685f34002edfbe4 to your computer and use it in GitHub Desktop.
import Scrollbar, { ScrollbarPlugin } from 'smooth-scrollbar'
class InvertDeltaPlugin extends ScrollbarPlugin {
static pluginName = 'invertDelta'
static defaultOptions = {
events: [],
}
transformDelta(delta, fromEvent) {
if (this.shouldInvertDelta(fromEvent)) {
return {
x: delta.y,
y: delta.x
}
}
return delta
}
shouldInvertDelta(fromEvent) {
return this.options.events.some(rule => fromEvent.type.match(rule))
}
}
Scrollbar.use(InvertDeltaPlugin)
export const scrollbarHorizontal = {
mounted () {
this.initScrollbar()
},
beforeDestroy () {
Scrollbar.destroy()
},
methods: {
initScrollbar () {
const el = document.querySelector('[data-scroll-horizontal]')
Scrollbar.init(el, {
plugins: {
invertDelta: {
events: [/wheel/],
},
},
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment