mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
26 lines
768 B
TypeScript
26 lines
768 B
TypeScript
import normalizeWheel from 'normalize-wheel-es'
|
|
|
|
import type { DirectiveBinding, ObjectDirective } from 'vue'
|
|
import type { NormalizedWheelEvent } from 'normalize-wheel-es'
|
|
|
|
const mousewheel = function (
|
|
element: HTMLElement,
|
|
callback: (e: WheelEvent, normalized: NormalizedWheelEvent) => void
|
|
) {
|
|
if (element && element.addEventListener) {
|
|
const fn = function (this: HTMLElement, event: WheelEvent) {
|
|
const normalized = normalizeWheel(event)
|
|
callback && Reflect.apply(callback, this, [event, normalized])
|
|
}
|
|
element.addEventListener('wheel', fn, { passive: true })
|
|
}
|
|
}
|
|
|
|
const Mousewheel: ObjectDirective = {
|
|
beforeMount(el: HTMLElement, binding: DirectiveBinding) {
|
|
mousewheel(el, binding.value)
|
|
},
|
|
}
|
|
|
|
export default Mousewheel
|