Skip to content

useMouseInElement

Reactive mouse position related to an element

Demo

Hover me
x: 0
y: 0
sourceType: null
elementX: 0
elementY: 0
elementPositionX: 0
elementPositionY: 0
elementHeight: 0
elementWidth: 0
isOutside: true

Usage

vue
<script setup>
import { ref } from 'vue'
import { useMouseInElement } from './'

const target = ref(null)

const { x, y, isOutside } = useMouseInElement(target)
</script>

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