2021-09-27 09:55:40 +08:00
|
|
|
import normalizeWheel from 'normalize-wheel-es'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { isFirefox } from '@element-plus/utils'
|
2022-03-25 15:35:56 +08:00
|
|
|
import type { DirectiveBinding, ObjectDirective } from 'vue'
|
2020-10-20 10:31:47 +08:00
|
|
|
|
|
|
|
const mousewheel = function (element, callback) {
|
|
|
|
if (element && element.addEventListener) {
|
2021-10-30 11:31:00 +08:00
|
|
|
const fn = function (this: any, event) {
|
2020-10-20 10:31:47 +08:00
|
|
|
const normalized = normalizeWheel(event)
|
2022-03-08 14:03:32 +08:00
|
|
|
callback && Reflect.apply(callback, this, [event, normalized])
|
2020-10-20 10:31:47 +08:00
|
|
|
}
|
2021-10-30 11:31:00 +08:00
|
|
|
if (isFirefox()) {
|
2020-10-20 10:31:47 +08:00
|
|
|
element.addEventListener('DOMMouseScroll', fn)
|
|
|
|
} else {
|
|
|
|
element.onmousewheel = fn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Mousewheel: ObjectDirective = {
|
2021-09-09 19:41:10 +08:00
|
|
|
beforeMount(el: HTMLElement, binding: DirectiveBinding) {
|
2020-10-20 10:31:47 +08:00
|
|
|
mousewheel(el, binding.value)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Mousewheel
|