-
-
Save jesperlandberg/4add9392bcc476884685f34002edfbe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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