wave.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="page">
  3. <svg class="waves" viewBox="0 24 150 24" preserveAspectRatio="none">
  4. <defs>
  5. <path id="wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"/>
  6. </defs>
  7. <use class="wave" xlink:href="#wave" :fill="color1" x="50" y="10">
  8. <animateTransform attributeName="transform" attributeType="XML" type="translate" from="-90 0" to="85 0"
  9. dur="3.2s" repeatCount="indefinite"/>
  10. </use>
  11. </svg>
  12. <svg class="waves" viewBox="0 24 180 24" preserveAspectRatio="none">
  13. <defs>
  14. <path id="wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"/>
  15. </defs>
  16. <use class="wave" xlink:href="#wave" :fill="color2" x="50" y="0">
  17. <animateTransform attributeName="transform" attributeType="XML" type="translate" from="-90 0" to="85 0"
  18. dur="6.2s" repeatCount="indefinite"/>
  19. </use>
  20. </svg>
  21. <svg class="waves" viewBox="0 24 150 24" preserveAspectRatio="none">
  22. <defs>
  23. <path id="wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"/>
  24. </defs>
  25. <use class="wave" xlink:href="#wave" :fill="color3" x="150" y="10">
  26. <animateTransform attributeName="transform" attributeType="XML" type="translate" from="-90 0" to="85 0"
  27. dur="12.2s" repeatCount="indefinite"/>
  28. </use>
  29. </svg>
  30. <svg class="waves" viewBox="0 24 150 24" preserveAspectRatio="none">
  31. <defs>
  32. <path id="wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"/>
  33. </defs>
  34. </svg>
  35. </div>
  36. </template>
  37. <script>
  38. export default {
  39. name: 'wave',
  40. props: {
  41. color: {
  42. type: String,
  43. default: '#32B5F3'
  44. }
  45. },
  46. watch: {
  47. color: {
  48. handler () {
  49. this.init()
  50. },
  51. immediate: true
  52. }
  53. },
  54. data () {
  55. return {
  56. color1: '',
  57. color2: '',
  58. color3: ''
  59. }
  60. },
  61. methods: {
  62. init () {
  63. this.color1 = this.hexToRGB(this.color, 0.1)
  64. this.color2 = this.hexToRGB(this.color, 0.3)
  65. this.color3 = this.hexToRGB(this.color, 0.5)
  66. },
  67. hexToRGB (hex, alpha) {
  68. const r = parseInt(hex.slice(1, 3), 16)
  69. const g = parseInt(hex.slice(3, 5), 16)
  70. const b = parseInt(hex.slice(5, 7), 16)
  71. if (alpha) {
  72. return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + alpha + ')'
  73. } else {
  74. return 'rgb(' + r + ', ' + g + ', ' + b + ')'
  75. }
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang='scss' scoped>
  81. .page {
  82. width: 100%;
  83. height: 50px;
  84. position: relative;
  85. overflow: hidden;
  86. border-radius: 10px;
  87. .waves {
  88. width: 100%;
  89. position: absolute;
  90. bottom: 0;
  91. left: 0;
  92. z-index: 1;
  93. }
  94. }
  95. </style>