2020-10-20 10:31:47 +08:00
|
|
|
import normalizeWheel from 'normalize-wheel'
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2020-10-20 10:31:47 +08:00
|
|
|
import type { ObjectDirective } from 'vue'
|
|
|
|
|
|
|
|
const isFirefox =
|
|
|
|
typeof navigator !== 'undefined' &&
|
|
|
|
navigator.userAgent.toLowerCase().indexOf('firefox') > -1
|
|
|
|
|
|
|
|
const mousewheel = function (element, callback) {
|
|
|
|
if (element && element.addEventListener) {
|
|
|
|
const fn = function (event) {
|
|
|
|
const normalized = normalizeWheel(event)
|
|
|
|
callback && callback.apply(this, [event, normalized])
|
|
|
|
}
|
|
|
|
if (isFirefox) {
|
|
|
|
element.addEventListener('DOMMouseScroll', fn)
|
|
|
|
} else {
|
|
|
|
element.onmousewheel = fn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Mousewheel: ObjectDirective = {
|
|
|
|
beforeMount(el, binding) {
|
|
|
|
mousewheel(el, binding.value)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Mousewheel
|