element-plus/packages/directives/mousewheel/index.ts
三咲智子 6503e55277
refactor(utils): migrate utils (#5949)
* refactor(utils-v2): migrate utils

* refactor(utils-v2): migrate utils

* refactor(utils-v2): migrate utils

* refactor(utils): remove

* refactor(utils): rename

* refactor(utils): move EVENT_CODE to constants

* refactor: remove generic
2022-02-11 11:03:15 +08:00

26 lines
711 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 && callback.apply(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