mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
2985a71751
Co-authored-by: winerlu <winerlu@tencent.com> Co-authored-by: zazzaz <izazzaz@hotmail.com>
29 lines
715 B
TypeScript
29 lines
715 B
TypeScript
import normalizeWheel from 'normalize-wheel'
|
|
import type { ObjectDirective } from 'vue'
|
|
|
|
const isFirefox =
|
|
typeof navigator !== 'undefined' &&
|
|
navigator.userAgent.toLowerCase().indexOf('firefox') > -1
|
|
|
|
const mousewheel = function (element, callback) {
|
|
if (element && element.addEventListener) {
|
|
const fn = function (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, binding) {
|
|
mousewheel(el, binding.value)
|
|
},
|
|
}
|
|
|
|
export default Mousewheel
|