element-plus/packages/directives/mousewheel/index.ts
TANGENNT 9b399385e0
fix(directives): use standard wheel event with passive option (#7256)
Both DOMMouseScroll and mousewheel event are non-standard now. And "[Violation]" warning will be
printed in console without setting `passive: true`.

fix #7016 #2016
2022-04-25 23:19:59 +08:00

21 lines
606 B
TypeScript

import normalizeWheel from 'normalize-wheel-es'
import type { DirectiveBinding, ObjectDirective } 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])
}
element.addEventListener('wheel', fn, { passive: true })
}
}
const Mousewheel: ObjectDirective = {
beforeMount(el: HTMLElement, binding: DirectiveBinding) {
mousewheel(el, binding.value)
},
}
export default Mousewheel