animation.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="content" :style="{'--color': color, '--playState': playState}">
  3. <view v-if="type === 'hollowDots'" class="refresh hollow-dots-spinner">
  4. <view class="dot"></view>
  5. <view class="dot"></view>
  6. <view class="dot"></view>
  7. </view>
  8. <view v-if="type === 'halfCircle'" class="refresh half-circle-spinner">
  9. <view class="circle circle-1"></view>
  10. <view class="circle circle-2"></view>
  11. </view>
  12. <view v-if="type === 'swappingSquares'" class="refresh swapping-squares-spinner">
  13. <view class="square"></view>
  14. <view class="square"></view>
  15. <view class="square"></view>
  16. <view class="square"></view>
  17. </view>
  18. <view class="loader refresh" v-if="type ==='loader'">
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'animation',
  25. props: {
  26. type: {
  27. type: String,
  28. default: 'hollowDots'
  29. },
  30. color: {
  31. type: String,
  32. default: '#04C4C4'
  33. },
  34. playState: {
  35. type: String,
  36. default: 'paused'
  37. }
  38. },
  39. data() {
  40. return {
  41. }
  42. },
  43. onLoad() {
  44. },
  45. methods: {
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. $color: var(--color);
  51. $playState: var(--playState);
  52. .refresh {
  53. width: 100%;
  54. height: 100rpx;
  55. display: flex;
  56. align-items: center;
  57. justify-content: center;
  58. box-sizing: border-box;
  59. view {
  60. animation-play-state: $playState !important;
  61. }
  62. }
  63. /* HollowDots */
  64. .hollow-dots-spinner .dot {
  65. width: 30rpx;
  66. height: 30rpx;
  67. margin: 0 calc(30rpx / 2);
  68. border: calc(30rpx / 5) solid $color;
  69. border-radius: 50%;
  70. float: left;
  71. transform: scale(0);
  72. animation: hollowDots 1000ms ease infinite 0ms;
  73. }
  74. .hollow-dots-spinner .dot:nth-child(1) {
  75. animation-delay: calc(300ms * 1);
  76. }
  77. .hollow-dots-spinner .dot:nth-child(2) {
  78. animation-delay: calc(300ms * 2);
  79. }
  80. .hollow-dots-spinner .dot:nth-child(3) {
  81. animation-delay: calc(300ms * 3);
  82. }
  83. @keyframes hollowDots {
  84. 50% {
  85. transform: scale(1);
  86. opacity: 1;
  87. }
  88. 100% {
  89. opacity: 0;
  90. }
  91. }
  92. /* halfCircle */
  93. .half-circle-spinner .circle {
  94. content: "";
  95. position: absolute;
  96. width: 60rpx;
  97. height: 60rpx;
  98. border-radius: 100%;
  99. border: calc(60rpx / 10) solid transparent;
  100. }
  101. .half-circle-spinner .circle.circle-1 {
  102. border-top-color: $color;
  103. animation: halfCircle 1s infinite;
  104. }
  105. .half-circle-spinner .circle.circle-2 {
  106. border-bottom-color: $color;
  107. animation: halfCircle 1s infinite alternate;
  108. }
  109. @keyframes halfCircle {
  110. 0% {
  111. transform: rotate(0deg);
  112. }
  113. 100% {
  114. transform: rotate(360deg);
  115. }
  116. }
  117. /* swappingSquares */
  118. .swapping-squares-spinner {
  119. position: relative;
  120. }
  121. .swapping-squares-spinner .square {
  122. height: calc(65rpx * 0.25 / 1.3);
  123. width: calc(65rpx * 0.25 / 1.3);
  124. animation-duration: 1000ms;
  125. border: calc(65rpx * 0.04 / 1.3) solid $color;
  126. margin-right: auto;
  127. margin-left: auto;
  128. position: absolute;
  129. animation-iteration-count: infinite;
  130. }
  131. .swapping-squares-spinner .square:nth-child(1) {
  132. animation-name: swappingSquares-child-1;
  133. animation-delay: 500ms;
  134. }
  135. .swapping-squares-spinner .square:nth-child(2) {
  136. animation-name: swappingSquares-child-2;
  137. animation-delay: 0ms;
  138. }
  139. .swapping-squares-spinner .square:nth-child(3) {
  140. animation-name: swappingSquares-child-3;
  141. animation-delay: 500ms;
  142. }
  143. .swapping-squares-spinner .square:nth-child(4) {
  144. animation-name: swappingSquares-child-4;
  145. animation-delay: 0ms;
  146. }
  147. @keyframes swappingSquares-child-1 {
  148. 50% {
  149. transform: translate(150%, 150%) scale(2, 2);
  150. }
  151. }
  152. @keyframes swappingSquares-child-2 {
  153. 50% {
  154. transform: translate(-150%, 150%) scale(2, 2);
  155. }
  156. }
  157. @keyframes swappingSquares-child-3 {
  158. 50% {
  159. transform: translate(-150%, -150%) scale(2, 2);
  160. }
  161. }
  162. @keyframes swappingSquares-child-4 {
  163. 50% {
  164. transform: translate(150%, -150%) scale(2, 2);
  165. }
  166. }
  167. // 魔方旋转
  168. $colors: hsla(337, 84, 48, 0.75) hsla(160, 50, 48, 0.75) hsla(190, 61, 65, 0.75) hsla(41, 82, 52, 0.75);
  169. $size: 2.5em;
  170. $thickness: 0.5em;
  171. $lat: ($size - $thickness) / 2;
  172. $offset: $lat - $thickness;
  173. .loader {
  174. // position: relative;
  175. // width: $size;
  176. // height: $size;
  177. transform: rotate(165deg);
  178. &:before,
  179. &:after {
  180. content: '';
  181. position: absolute;
  182. top: 50%;
  183. left: 50%;
  184. display: block;
  185. width: $thickness;
  186. height: $thickness;
  187. border-radius: $thickness / 2;
  188. transform: translate(-50%, -50%);
  189. }
  190. &:before {
  191. animation: before 2s infinite;
  192. }
  193. &:after {
  194. animation: after 2s infinite;
  195. }
  196. }
  197. @keyframes before {
  198. 0% {
  199. width: $thickness;
  200. box-shadow:
  201. $lat (-$offset) nth($colors, 1),
  202. (-$lat) $offset nth($colors, 3);
  203. }
  204. 35% {
  205. width: $size;
  206. box-shadow:
  207. 0 (-$offset) nth($colors, 1),
  208. 0 $offset nth($colors, 3);
  209. }
  210. 70% {
  211. width: $thickness;
  212. box-shadow:
  213. (-$lat) (-$offset) nth($colors, 1),
  214. $lat $offset nth($colors, 3);
  215. }
  216. 100% {
  217. box-shadow:
  218. $lat (-$offset) nth($colors, 1),
  219. (-$lat) $offset nth($colors, 3);
  220. }
  221. }
  222. @keyframes after {
  223. 0% {
  224. height: $thickness;
  225. box-shadow:
  226. $offset $lat nth($colors, 2),
  227. (-$offset) (-$lat) nth($colors, 4);
  228. }
  229. 35% {
  230. height: $size;
  231. box-shadow:
  232. $offset 0 nth($colors, 2),
  233. (-$offset) 0 nth($colors, 4);
  234. }
  235. 70% {
  236. height: $thickness;
  237. box-shadow:
  238. $offset (-$lat) nth($colors, 2),
  239. (-$offset) $lat nth($colors, 4);
  240. }
  241. 100% {
  242. box-shadow:
  243. $offset $lat nth($colors, 2),
  244. (-$offset) (-$lat) nth($colors, 4);
  245. }
  246. }
  247. .loader {
  248. // position: absolute;
  249. // top: calc(50% - #{$size / 2});
  250. // left: calc(50% - #{$size / 2});
  251. // z-index: 999;
  252. }
  253. </style>