useElementHover ​
Reactive element's hover state.
Demo ​
Usage ​
vue
<script setup>
import { useElementHover } from '@vueuse/core'
const myHoverableElement = ref()
const isHovered = useElementHover(myHoverableElement)
</script>
<template>
<button ref="myHoverableElement">
{{ isHovered }}
</button>
</template>
Directive Usage ​
This function also provides a directive version via the
@vueuse/components
package. Learn more about the usage.
vue
<script setup lang="ts">
import { ref } from 'vue'
import { vElementHover } from '@vueuse/components'
const isHovered = ref(false)
function onHover(state: boolean) {
isHovered.value = state
}
</script>
<template>
<button v-element-hover="onHover">
{{ isHovered ? 'Thank you!' : 'Hover me' }}
</button>
</template>
Type Declarations ​
typescript
export interface UseElementHoverOptions extends ConfigurableWindow {
delayEnter?: number
delayLeave?: number
}
export declare function useElementHover(
el: MaybeRefOrGetter<EventTarget | null | undefined>,
options?: UseElementHoverOptions,
): Ref<boolean>
Source ​
Contributors ​
Anthony Fu
webfansplz
Jelf
geekreal
cx33
Joe Maylor