generated from Tahul/vue-composable-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
I'm trying to reproduce a minimal drag example, where the user can drag a component somewhere, and it stays there. Problem is: the first time the user drags the component, it stays there, but as soon as he tries to re-drag the component, it goes back to the (0,0) position and begins the next drag from there.
My code is the following:
<template>
<div ref="widgetRef" class="widget">
<span>Widget</span>
</div>
</template>
<script setup lang="ts">
import { useGesture } from '@vueuse/gesture'
import { type PermissiveMotionProperties, useMotionProperties, useSpring } from '@vueuse/motion'
import { ref } from 'vue'
const widgetRef = ref()
const { motionProperties } = useMotionProperties(widgetRef, {
cursor: 'grab',
})
const { set } = useSpring(motionProperties as Partial<PermissiveMotionProperties>)
useGesture(
{
onDrag: ({ movement: [x, y] }) => set({ x, y, scale: 2 }),
onDragEnd: () => set({ scale: 1 }),
},
{
domTarget: widgetRef,
}
)
</script>
<style scoped>
.widget {
padding: 10px;
margin: 5px;
background-color: antiquewhite;
}
</style>
stefnotch and ALiangLiang
Metadata
Metadata
Assignees
Labels
No labels