index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div
  3. class="avatar-wrap"
  4. :style="{ '--width': size + 'px' }"
  5. >
  6. <div class="cycle-wrap">
  7. <div
  8. class="avatar"
  9. :class="{ border }"
  10. :style="{ backgroundImage: `url(${avatar})` }"
  11. ></div>
  12. <template v-if="living">
  13. <div class="cycle cycle-1"></div>
  14. <div class="cycle cycle-2"></div>
  15. <div class="cycle cycle-3"></div
  16. ></template>
  17. </div>
  18. <div class="border"></div>
  19. </div>
  20. </template>
  21. <script lang="ts" setup>
  22. withDefaults(
  23. defineProps<{
  24. avatar: string;
  25. size: number;
  26. living?: boolean;
  27. border?: boolean;
  28. }>(),
  29. {
  30. avatar: '',
  31. size: 100,
  32. living: false,
  33. border: false,
  34. }
  35. );
  36. </script>
  37. <style lang="scss" scoped>
  38. .avatar-wrap {
  39. position: relative;
  40. @keyframes scaleCycle {
  41. 0% {
  42. opacity: 1;
  43. transform: scale(1);
  44. }
  45. 100% {
  46. opacity: 0;
  47. transform: scale(1.5);
  48. }
  49. }
  50. .cycle-wrap {
  51. position: relative;
  52. width: var(--width);
  53. height: var(--width);
  54. .avatar {
  55. display: inline-block;
  56. box-sizing: border-box;
  57. margin: 0 auto;
  58. width: var(--width);
  59. height: var(--width);
  60. border-radius: 50%;
  61. cursor: pointer;
  62. @extend %containBg;
  63. &.border {
  64. border: 1px solid $theme-color-gold;
  65. }
  66. }
  67. .cycle {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. width: var(--width);
  72. height: var(--width);
  73. border: 1px solid $theme-color-gold;
  74. border-radius: 50%;
  75. animation: scaleCycle 1.5s linear infinite;
  76. &.cycle-1 {
  77. animation-delay: 0;
  78. }
  79. &.cycle-2 {
  80. animation-delay: 0.5s;
  81. }
  82. &.cycle-3 {
  83. animation-delay: 1s;
  84. }
  85. }
  86. }
  87. }
  88. </style>