useMouseInElement

Reactive mouse position related to an element

Usage















 






<template>
  <div ref="target">
    <h1>Hello world</h1>
  </div>
</template>

<script>
import { ref } from 'vue'
import { useMouseInElement } from '@vueuse/core'

export default {
  setup() {
    const el = ref(null)

    const { x, y, isOutside } = useMouseInElement(el)

    return { x, y, isOutside }
  }
}
</script>

Type Declarations

export interface MouseInElementOptions extends MouseOptions {
  handleOutside?: boolean
}
/**
 * Reactive mouse position related to an element.
 *
 * @see   {@link /useMouseInElement}
 * @param target
 * @param options
 */
export declare function useMouseInElement(
  target?: MaybeRef<Element | null | undefined>,
  options?: MouseInElementOptions
): {
  x: Ref<number>
  y: Ref<number>
  sourceType: Ref<MouseSourceType>
  elementX: Ref<number>
  elementY: Ref<number>
  elementPositionX: Ref<number>
  elementPositionY: Ref<number>
  elementHeight: Ref<number>
  elementWidth: Ref<number>
  isOutside: Ref<boolean>
  stop: () => void
}

Source

SourceDemoDocs