index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="hc-border-neon" :class="[isAlign, isNeon ? 'is-neon':'']">
  3. <i class="top"/>
  4. <i class="bottom"/>
  5. <i class="left"/>
  6. <i class="right"/>
  7. </div>
  8. </template>
  9. <script setup>
  10. import {ref, watch} from "vue";
  11. const props = defineProps({
  12. align: {
  13. type: String,
  14. default: 'left'
  15. },
  16. neon: {
  17. type: Boolean,
  18. default: false
  19. },
  20. })
  21. const isAlign = ref(props.align)
  22. const isNeon = ref(props.neon)
  23. //监听
  24. watch(() => [
  25. props.align,
  26. props.neon,
  27. ], ([val, neon]) => {
  28. isAlign.value = val
  29. isNeon.value = neon
  30. })
  31. </script>
  32. <style lang="scss">
  33. html.dark {
  34. .hc-border-neon {
  35. position: absolute;
  36. top: 0;
  37. left: 0;
  38. bottom: 0;
  39. right: 0;
  40. border-radius: inherit;
  41. overflow: hidden;
  42. i.top {
  43. position: absolute;
  44. top: 0;
  45. right: -100%;
  46. height: 2px;
  47. width: 100%;
  48. background-image: linear-gradient(
  49. 270deg,
  50. transparent,
  51. #03e9f4,
  52. transparent
  53. );
  54. }
  55. i.bottom {
  56. position: absolute;
  57. bottom: 0;
  58. left: -100%;
  59. height: 2px;
  60. width: 100%;
  61. background-image: linear-gradient(
  62. 270deg,
  63. transparent,
  64. #03e9f4,
  65. transparent
  66. );
  67. }
  68. i.left {
  69. position: absolute;
  70. width: 2px;
  71. height: 100%;
  72. top: -100%;
  73. left: 0;
  74. background-image: linear-gradient(
  75. 0deg,
  76. transparent,
  77. #03e9f4,
  78. transparent
  79. );
  80. }
  81. i.right {
  82. position: absolute;
  83. width: 2px;
  84. height: 100%;
  85. bottom: -100%;
  86. right: 0;
  87. background-image: linear-gradient(
  88. 360deg,
  89. transparent,
  90. #03e9f4,
  91. transparent
  92. );
  93. }
  94. &.left {
  95. i.left {
  96. animation: hc-border-neon-two 4s linear 1s infinite;
  97. }
  98. i.bottom {
  99. animation: hc-border-neon-one 4s linear 2s infinite;
  100. }
  101. i.right {
  102. animation: hc-border-neon-four 4s linear 3s infinite;
  103. }
  104. i.top {
  105. animation: hc-border-neon-three 4s linear infinite;
  106. }
  107. &.is-neon {
  108. i.left {
  109. bottom: -100%;
  110. right: initial;
  111. top: initial;
  112. left: 0;
  113. animation: hc-border-neon-four 4s linear 1s infinite;
  114. }
  115. i.top {
  116. left: 0;
  117. right: initial;
  118. bottom: initial;
  119. animation: hc-border-neon-one 4s linear 2s infinite;
  120. }
  121. i.right {
  122. top: 0;
  123. bottom: initial;
  124. animation: hc-border-neon-two 4s linear 3s infinite;
  125. }
  126. i.bottom {
  127. bottom: 0;
  128. left: initial;
  129. right: -100%;
  130. animation: hc-border-neon-three 4s linear infinite;
  131. }
  132. }
  133. }
  134. &.right {
  135. i.right {
  136. animation: hc-border-neon-four 4s linear 1s infinite;
  137. }
  138. i.top {
  139. animation: hc-border-neon-three 4s linear 2s infinite;
  140. }
  141. i.left {
  142. animation: hc-border-neon-two 4s linear 3s infinite;
  143. }
  144. i.bottom {
  145. animation: hc-border-neon-one 4s linear infinite;
  146. }
  147. &.is-neon {
  148. i.left {
  149. bottom: -100%;
  150. right: initial;
  151. top: initial;
  152. left: 0;
  153. animation: hc-border-neon-four 4s linear 3s infinite;
  154. }
  155. i.right {
  156. top: 0;
  157. bottom: initial;
  158. animation: hc-border-neon-two 4s linear 1s infinite;
  159. }
  160. i.top {
  161. left: 0;
  162. right: initial;
  163. bottom: initial;
  164. animation: hc-border-neon-one 4s linear infinite;
  165. }
  166. i.bottom {
  167. bottom: 0;
  168. left: initial;
  169. right: -100%;
  170. animation: hc-border-neon-three 4s linear 2s infinite;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. @keyframes hc-border-neon-one {
  177. 0% {
  178. left: -100%;
  179. }
  180. 50%,
  181. 100% {
  182. left: 100%;
  183. }
  184. }
  185. @keyframes hc-border-neon-two {
  186. 0% {
  187. top: -100%;
  188. }
  189. 50%,
  190. 100% {
  191. top: 100%;
  192. }
  193. }
  194. @keyframes hc-border-neon-three {
  195. 0% {
  196. right: -100%;
  197. }
  198. 50%,
  199. 100% {
  200. right: 100%;
  201. }
  202. }
  203. @keyframes hc-border-neon-four {
  204. 0% {
  205. bottom: -100%;
  206. }
  207. 50%,
  208. 100% {
  209. bottom: 100%;
  210. }
  211. }
  212. </style>