motion icon indicating copy to clipboard operation
motion copied to clipboard

useSpring example not working

Open boydenhartog opened this issue 2 years ago • 3 comments

Hi,

I've used the useSpring example from the documentation but it doesn't seem to work. Am I missing something or is the documentation incorrect? This is my very simple component. I have globally installed vue motion in my app.

When I click the div, I see 'click' appear in the console but no animation is triggered.

I get an error in this codesandbox when triggering the animation that I'm not getting in my local app, I'm not sure if it's related. Cannot read properties of undefined (reading 'apply') https://codesandbox.io/s/vueuse-motion-forked-i76zv6?file=/src/components/Bar.vue

Can anyone shed some light?

<template>
  <div ref="target" class="bar" @click="onClick"></div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useSpring } from "@vueuse/motion";

const target = ref<HTMLElement>()

const { set, values, stop } = useSpring(target as any, {
  damping: 50,
  stiffness: 220,
})

const onClick = () => {
  console.log('click')
  set({
    scale: 3,
  })
}

const onClickOut = () => {
  set({
    scale: 1,
  })
}

const stopTransitions = () => {
  stop()
}
</script>

<style lang="scss">
.bar {
  height: 100px;
  width: 40px;
  background-color: red;
}
</style>

boydenhartog avatar Apr 14 '22 10:04 boydenhartog

@boydenhartog I think the doc might have been changed and us outdated. After looking at useSpring's implementation, I think you can try using it like this: stackblitz demo with Nuxt 3

didavid61202 avatar May 31 '22 06:05 didavid61202

I updated @didavid61202 's great work to use the reactiveTransform composable from Vue Motion. That made a bit more sense to me and I'm guessing that's how the authors of this library intended it to be used?

Basically reactiveTransform outputs a state variable which useSpring can animate, which is then tied to a transform reactive variable which can then be bound to the actual element's style.

https://stackblitz.com/edit/nuxt-starter-vujfqb?file=app.vue

blisst avatar Jun 10 '23 16:06 blisst

The example in the docs is still not working 1.5 years in

fgd007 avatar Oct 20 '23 10:10 fgd007

Resolved by #181

BobbieGoede avatar Apr 19 '24 09:04 BobbieGoede