mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
refactor(components): [image] use standard wheel event (#11107)
This commit is contained in:
parent
515f4b7931
commit
843d07dec0
@ -95,7 +95,7 @@ import { isNumber, useEventListener } from '@vueuse/core'
|
||||
import { throttle } from 'lodash-unified'
|
||||
import { useLocale, useNamespace, useZIndex } from '@element-plus/hooks'
|
||||
import { EVENT_CODE } from '@element-plus/constants'
|
||||
import { isFirefox, keysOf } from '@element-plus/utils'
|
||||
import { keysOf } from '@element-plus/utils'
|
||||
import ElIcon from '@element-plus/components/icon'
|
||||
import {
|
||||
ArrowLeft,
|
||||
@ -124,8 +124,6 @@ const modes: Record<'CONTAIN' | 'ORIGINAL', ImageViewerMode> = {
|
||||
},
|
||||
}
|
||||
|
||||
const mousewheelEventName = isFirefox() ? 'DOMMouseScroll' : 'mousewheel'
|
||||
|
||||
defineOptions({
|
||||
name: 'ElImageViewer',
|
||||
})
|
||||
@ -237,26 +235,17 @@ function registerEventListener() {
|
||||
break
|
||||
}
|
||||
})
|
||||
const mousewheelHandler = throttle(
|
||||
(e: WheelEvent | any /* TODO: wheelDelta is deprecated */) => {
|
||||
const delta = e.wheelDelta ? e.wheelDelta : -e.detail
|
||||
if (delta > 0) {
|
||||
handleActions('zoomIn', {
|
||||
zoomRate: props.zoomRate,
|
||||
enableTransition: false,
|
||||
})
|
||||
} else {
|
||||
handleActions('zoomOut', {
|
||||
zoomRate: props.zoomRate,
|
||||
enableTransition: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
const mousewheelHandler = throttle((e: WheelEvent) => {
|
||||
const delta = e.deltaY || e.deltaX
|
||||
handleActions(delta < 0 ? 'zoomIn' : 'zoomOut', {
|
||||
zoomRate: props.zoomRate,
|
||||
enableTransition: false,
|
||||
})
|
||||
})
|
||||
|
||||
scopeEventListener.run(() => {
|
||||
useEventListener(document, 'keydown', keydownHandler)
|
||||
useEventListener(document, mousewheelEventName, mousewheelHandler)
|
||||
useEventListener(document, 'wheel', mousewheelHandler)
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user