lime-animate-it.uvue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view style="height: 500px;">
  3. <view ref="viewRef" :animation="animationData" class="test"></view>
  4. <view ref="viewRef2" class="test"></view>
  5. <!-- <view :style="style" class="test"></view> -->
  6. </view>
  7. <button @click="onClick">播放</button>
  8. <button @click="onStop">停止</button>
  9. </template>
  10. <script setup>
  11. import {createAnimation, CreateAnimationOptions} from '@/uni_modules/lime-animateIt'
  12. const viewRef = ref<UniElement|null>(null)
  13. const viewRef2 = ref<UniElement|null>(null)
  14. // 没有作用,只是为了跟小程序兼容
  15. const animationData = ref({})
  16. const animation = createAnimation({
  17. duration: 1000,
  18. transformOrigin: '50% 50%',
  19. timingFunction: 'ease',
  20. } as CreateAnimationOptions)
  21. animation.scaleX(0.5).translateX(200).step()
  22. animation.top(200).scaleX(1.8).step({duration: 600})
  23. animation.top(100).left(-200).step({duration: 2000})
  24. // 非小程序export不导致出任何内容。
  25. animationData.value = animation.export(viewRef,2)
  26. animation.onFinish = ()=>{
  27. console.log('onFinish')
  28. }
  29. const onClick = ()=>{
  30. console.log('点击')
  31. animation.play()
  32. }
  33. const onStop = ()=>{
  34. animation.stop()
  35. }
  36. const style = ref('')
  37. setTimeout(()=>{
  38. viewRef2.value!.style.setProperty('background-color', '#FF0000')
  39. style.value = 'transform: scaleX(0.5) translateX(100px)';
  40. // style.value = 'transform: rotate(45deg)'
  41. setTimeout(()=>{
  42. style.value = 'transform: scaleX(1.8) translateX(100px) translateY(100px)';
  43. },1000)
  44. },1000)
  45. </script>
  46. <style lang="scss">
  47. .test {
  48. position: absolute;
  49. background: red;
  50. height: 100rpx;
  51. width: 100rpx;
  52. // transition-duration: 300ms;
  53. // transition-timing-function: ease;
  54. // transition-property: transform;
  55. // transform: rotate(45deg);
  56. }
  57. </style>