2021-09-27 09:55:40 +08:00
|
|
|
import normalizeWheel from 'normalize-wheel-es'
|
2021-10-30 11:31:00 +08:00
|
|
|
import { isFirefox } from '@element-plus/utils/util'
|
2021-09-09 19:41:10 +08:00
|
|
|
import type { ObjectDirective, DirectiveBinding } 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)
|
|
|
|
callback && callback.apply(this, [event, normalized])
|
|
|
|
}
|
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
|