mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 20:58:22 +08:00
b8c38a9fe5
* chore: enhance eslint rules * chore: enhance eslint rules
26 lines
720 B
TypeScript
26 lines
720 B
TypeScript
import normalizeWheel from 'normalize-wheel-es'
|
|
import { isFirefox } from '@element-plus/utils'
|
|
import type { ObjectDirective, DirectiveBinding } from 'vue'
|
|
|
|
const mousewheel = function (element, callback) {
|
|
if (element && element.addEventListener) {
|
|
const fn = function (this: any, event) {
|
|
const normalized = normalizeWheel(event)
|
|
callback && Reflect.apply(callback, this, [event, normalized])
|
|
}
|
|
if (isFirefox()) {
|
|
element.addEventListener('DOMMouseScroll', fn)
|
|
} else {
|
|
element.onmousewheel = fn
|
|
}
|
|
}
|
|
}
|
|
|
|
const Mousewheel: ObjectDirective = {
|
|
beforeMount(el: HTMLElement, binding: DirectiveBinding) {
|
|
mousewheel(el, binding.value)
|
|
},
|
|
}
|
|
|
|
export default Mousewheel
|