index.ts 768 B

12345678910111213141516171819202122232425
  1. import normalizeWheel from 'normalize-wheel-es'
  2. import type { DirectiveBinding, ObjectDirective } from 'vue'
  3. import type { NormalizedWheelEvent } from 'normalize-wheel-es'
  4. const mousewheel = function (
  5. element: HTMLElement,
  6. callback: (e: WheelEvent, normalized: NormalizedWheelEvent) => void
  7. ) {
  8. if (element && element.addEventListener) {
  9. const fn = function (this: HTMLElement, event: WheelEvent) {
  10. const normalized = normalizeWheel(event)
  11. callback && Reflect.apply(callback, this, [event, normalized])
  12. }
  13. element.addEventListener('wheel', fn, { passive: true })
  14. }
  15. }
  16. const Mousewheel: ObjectDirective = {
  17. beforeMount(el: HTMLElement, binding: DirectiveBinding) {
  18. mousewheel(el, binding.value)
  19. },
  20. }
  21. export default Mousewheel