animation.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="animation-element-wrapper">
  6. <view class="animation-element" :animation="animationData"></view>
  7. </view>
  8. <scroll-view class="animation-buttons" scroll-y="true">
  9. <button class="animation-button" @tap="rotate">旋转</button>
  10. <button class="animation-button" @tap="scale">缩放</button>
  11. <button class="animation-button" @tap="translate">移动</button>
  12. <button class="animation-button" @tap="skew">倾斜</button>
  13. <button class="animation-button" @tap="rotateAndScale">旋转并缩放</button>
  14. <button class="animation-button" @tap="rotateThenScale">旋转后缩放</button>
  15. <button class="animation-button" @tap="all">同时展示全部</button>
  16. <button class="animation-button" @tap="allInQueue">顺序展示全部</button>
  17. <button class="animation-button animation-button-reset" @tap="reset">还原</button>
  18. </scroll-view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. title: 'createAnimation',
  27. animationData: ''
  28. }
  29. },
  30. onUnload(){
  31. this.animationData = ''
  32. },
  33. onLoad() {
  34. this.animation = uni.createAnimation()
  35. },
  36. methods: {
  37. rotate: function () {
  38. this.animation.rotate(Math.random() * 720 - 360).step()
  39. this.animationData = this.animation.export()
  40. },
  41. scale: function () {
  42. this.animation.scale(Math.random() * 2).step()
  43. this.animationData = this.animation.export()
  44. },
  45. translate: function () {
  46. this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
  47. this.animationData = this.animation.export()
  48. },
  49. skew: function () {
  50. this.animation.skew(Math.random() * 90, Math.random() * 90).step()
  51. this.animationData = this.animation.export()
  52. },
  53. rotateAndScale: function () {
  54. this.animation.rotate(Math.random() * 720 - 360)
  55. .scale(Math.random() * 2)
  56. .step()
  57. this.animationData = this.animation.export()
  58. },
  59. rotateThenScale: function () {
  60. this.animation.rotate(Math.random() * 720 - 360).step()
  61. .scale(Math.random() * 2).step()
  62. this.animationData = this.animation.export()
  63. },
  64. all: function () {
  65. this.animation.rotate(Math.random() * 720 - 360)
  66. .scale(Math.random() * 2)
  67. .translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
  68. .skew(Math.random() * 90, Math.random() * 90)
  69. .step()
  70. this.animationData = this.animation.export()
  71. },
  72. allInQueue: function () {
  73. this.animation.rotate(Math.random() * 720 - 360).step()
  74. .scale(Math.random() * 2).step()
  75. .translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
  76. .skew(Math.random() * 90, Math.random() * 90).step()
  77. this.animationData = this.animation.export()
  78. },
  79. reset: function () {
  80. this.animation.rotate(0, 0)
  81. .scale(1)
  82. .translate(0, 0)
  83. .skew(0, 0)
  84. .step({
  85. duration: 0
  86. })
  87. this.animationData = this.animation.export()
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. .animation-element-wrapper {
  94. display: flex;
  95. width: 100%;
  96. padding-top: 150rpx;
  97. padding-bottom: 150rpx;
  98. justify-content: center;
  99. overflow: hidden;
  100. background-color: #ffffff;
  101. }
  102. .animation-element {
  103. width: 200rpx;
  104. height: 200rpx;
  105. background-color: #1AAD19;
  106. }
  107. .animation-buttons {
  108. padding:30rpx 0;
  109. width: 100%;
  110. /* height: 360rpx; */
  111. }
  112. .animation-button {
  113. float: left;
  114. width: 44%;
  115. margin: 15rpx 3%;
  116. }
  117. .animation-button-reset {
  118. width: 94%;
  119. }
  120. </style>