一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

CSS3如何实现发光边框特效 CSS3实现发光边框特效代码示例

时间:2022-06-25 14:02:23 编辑:袖梨 来源:一聚教程网

CSS3如何实现发光边框特效?本篇文章小编给大家分享一下CSS3实现发光边框特效代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

运行效果:

html


CSS

css;">body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  background: #010326;
}

.root {
  --glow_
  --animation_length: 2s;
  --delay_factor: 2;

  position: absolute;
  left: 50%;
  top: 50%;
  
  
  transform: translate(-50%, -50%) rotate(45deg);

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

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

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

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

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

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

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

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

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

js

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

热门栏目