CSS3 实现发光边框特效

网站建设 2023-01-28 21:39www.1681989.com免费网站

运行效果

html

<!-- This element is not visible. The DOM is generated by JavaScript -->
<div class="root" style="display: none;">
  <div>
    <div class="side left"></div>
    <div class="side "></div>
    <div class="side right"></div>
    <div class="side bottom"></div>
  </div>
</div>

CSS

body {
  marg: 0;
  width: 100vw;
  height: 100vh;
  background: #010326;
}

.root {
  --glow_width: 2px;
  --animation_length: 2s;
  --delay_factor: 2;

  position: absolute;
  left: 50%;
  : 50%;
  width: 300px;
  height: 300px;
  transform: translate(-50%, -50%) rotate(45deg);

/  Unment the le below to see how this system is set up  /
/   border: 1px dashed red; /
  overflow: hidden;
}

.side {
  position: absolute;
  : 0;
  left: 0;
}

.side.left,
.side.right {
  width: var(--glow_width);
  height: 0;
  background: lear-gradient(to bottom, transparent, #c03225, transparent);
  animation: heightAnim var(--animation_length) lear fite,
    hider calc(var(--delay_factor)  var(--animation_length))
      var(--animation_length) fite;
}

.side.,
.side.bottom {
  width: 100%;
  height: var(--glow_width);
  background: lear-gradient(to left, transparent, #c03225, transparent);
  animation: widthAnim var(--animation_length) 0s lear fite,
    hider calc(var(--delay_factor)  var(--animation_length))
      var(--animation_length) fite;
}

.side.right {
  left: auto;
  right: 0;
  height: 0;
  animation-delay: calc(var(--animation_length) / 2);
  animation-direction: normal, reverse;
}

.side.bottom {
  : auto;
  bottom: 0;
  width: 0;
  animation-delay: calc(var(--animation_length) / 2);
  animation-direction: normal, reverse;
}

@keyframes heightAnim {
  0% {
    height: 0px;
  }
  50% {
    height: 300px;
    transform: itial;
  }
  100% {
    transform: translate(0, 300px);
  }
}

@keyframes widthAnim {
  0% {
    width: 0px;
  }
  50% {
    width: 300px;
    transform: itial;
  }
  100% {
    transform: translate(300px, 0px);
  }
}

@keyframes hider {
  0%,
  50% {
    opacity: 0;
  }
  51%,
  100% {
    opacity: 1;
  }
}

js

let template = `<div class="root" style="transform: translate(-50%, -50%) rotate({{ value }})">
<div>
    <div class="side left"></div>
    <div class="side "></div>
    <div class="side right"></div>
    <div class="side bottom"></div>
  </div>
</div>`

let segments = 9
for(let i = -segments; i < segments; i++){
  document.body.nerHTML += template.replace("{{ value }}", 90/segments  i + "deg")
}

// document.body.nerHTML += template.replace("{{ value }}", 90/segments  0 + "deg")

以上就是CSS3 实现发光边框特效的详细内容,更多关于CSS3 发光边框特效的资料请关注狼蚁SEO其它相关文章!

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by