Line data Source code
1 : import type { Ref } from 'vue'
2 :
3 : import { useMouseInElement } from '@vueuse/core'
4 : import { ref, watch } from 'vue'
5 :
6 5 : export function useSliderFromMouse(target: Ref<HTMLElement | null>) {
7 5 : const position = ref(50)
8 5 : const { elementX, elementWidth, isOutside } = useMouseInElement(target)
9 :
10 5 : watch([elementX, elementWidth, isOutside], ([x, width, outside]) => {
11 0 : if (!outside && width > 0) {
12 0 : position.value = (x / width) * 100
13 : }
14 : })
15 :
16 5 : return position
17 : }
|