sound-wave.vue 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="SoundWave">
  3. <view
  4. v-for="i in 20"
  5. :key="i"
  6. class="Wave-line"
  7. :class="isPlay ? 'active' : ''"
  8. />
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. isPlay: false
  16. }
  17. },
  18. methods: {
  19. play() {
  20. this.isPlay = true
  21. },
  22. pause() {
  23. this.isPlay = false
  24. }
  25. }
  26. }
  27. </script>
  28. <style lang="scss" scoped>
  29. .SoundWave {
  30. width: 100%;
  31. height: 100%;
  32. display: flex;
  33. align-items: center;
  34. justify-content: space-between;
  35. .Wave-line {
  36. width: 4rpx;
  37. background: #FFFFFF;
  38. border-radius: 4rpx;
  39. @for $i from 1 through 20 {
  40. &:nth-of-type(#{$i}) {
  41. height: #{random(40)}rpx;
  42. }
  43. }
  44. &.active {
  45. @for $i from 1 through 20 {
  46. &:nth-of-type(#{$i}) {
  47. animation: load 2.5s #{(random(10)*0.2)+ 1}s infinite linear;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. @keyframes load {
  54. 0% {
  55. height: 100%;
  56. }
  57. 30% {
  58. height: 20%;
  59. }
  60. 60% {
  61. height: 60%;
  62. }
  63. 100% {
  64. height: 10%;
  65. }
  66. }
  67. </style>