在我的React.js应用程序中,我有一个正方形形状,我想在其中绘制两个在边界周围相互追逐的边界.追逐边界总是对立的,永远追不上对方.通过这种方式,我想创建一个效果,看起来像在下面的图像与霓虹灯黄色.我一直在努力做到这一点,现在我已经相当接近了,但我未能正确地完成追逐边界.它们似乎在绕着广场移动时破裂了,最后我实现了类似下面另一张图像的东西.

The current result I have achieved now.
Desired outcomeCurrent progress

Here is the that I have tried so far to solve my problem: const chasingBorders1 = keyframes`
  0% {
    clip-path: polygon(100% 0%, 100% 40%, 60% 0%, 100% 0%);
  }
  25% {
    clip-path: polygon(100% 60%, 100% 100%, 60% 60%, 100% 40%);
  }
  50% {
    clip-path: polygon(0% 100%, 40% 100%, 0% 60%, 40% 60%);
  }
  75% {
    clip-path: polygon(0% 0%, 0% 40%, 40% 0%, 40% 40%);
  }
  100% {
    clip-path: polygon(100% 0%, 100% 40%, 60% 0%, 100% 0%);
  }
`;

const chasingBorders2 = keyframes`
  0% {
    clip-path: polygon(0% 100%, 0% 60%, 40% 100%, 0% 100%);
  }
  25% {
    clip-path: polygon(0% 0%, 0% 40%, 40% 0%, 40% 40%);
  }
  50% {
    clip-path: polygon(100% 0%, 100% 40%, 60% 0%, 100% 0%);
  }
  75% {
    clip-path: polygon(100% 60%, 100% 100%, 60% 60%, 100% 40%);
  }
  100% {
    clip-path: polygon(0% 100%, 0% 60%, 40% 100%, 0% 100%);
  }
`;

const ModeBox = styled(motion.div)`
  position: absolute;
  top: 45px;
  left: 33.5%;
  background: #020202;
  border: solid 5px white;
  border-radius: 30px;
  width: 580px;
  height: 100px;
  z-index: 95;

  &::before, &::after {
    content: "";
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: solid 8px orange;
    border-radius: inherit;
    z-index: -1;
    box-shadow: 0 0 10px #6F5824, 0 0 15px #6F5824, 0 0 20px #6F5824;
  }

  &::before {
    animation: ${chasingBorders1} 4s infinite;
  }

  &::after {
    animation: ${chasingBorders2} 4s infinite;
  }
`;

推荐答案

作为选项,您可以应用线性渐变和旋转动画:

body {
  background-color: #000;
}

a{
  --border-radius: 16px;
  --border-width: 2px;
  padding: var(--border-width);
  border-radius: var(--border-radius);
  position: relative;
  overflow: hidden;
  will-change: transform;
  background-color: rgba(255,255,255,.1);
  display: inline-flex;
  color: #fff;
  text-decoration: none;
}


a span{
  padding: 12px 32px;
  background-color: #000;
  border-radius: calc(var(--border-radius) - var(--border-width));
}

a:before,
a:after {
  content: '';
  position: absolute;
  z-index: -1;
  width: 100%;
  aspect-ratio: 1;
  position: absolute;
  animation: rotate 4s linear infinite;
  inset: 50% auto auto 50%;
}

a:before {
  background: linear-gradient(to top, transparent 50%, orange);
  clip-path: polygon(0 0, 50% 0, 50% 50%, 0 50%);
}

a:after{
  clip-path: polygon(100% 100%,50% 100%,50% 50%, 100% 50%);
  background: linear-gradient(to bottom, transparent 50%, orange);
}

@keyframes rotate {
  0% {
    transform: translate(-50%,-50%) rotate(0);
  }
  100% {
    transform: translate(-50%,-50%) rotate(1turn);
  }
}
<a href="#"><span>Lorem ipsum.</span></a>

Css相关问答推荐

Tailwind CSS group-hover不适用于自定义前置码

VueJS CSS动画不会扩展到v-card/v-col之外

如何将另一种自定义位置 colored颜色 添加到三角形CSS中?

如何将Ant设计日期 Select 器的图标设置在输入 Select 器之前而不是之后

圆形按钮边框长度动画

:not() 适用于特定类中的所有 html 标签

带有 flex 的 CSS 空 div 以扩展并保持纵横比

使用 :checked 显示隐藏的侧面板

如何在每一行周围放置不同大小的阴影?

svg 背景图像位置始终在 Internet Explorer 中居中,尽管 background-position: left center;

悬停效果:展开底部边框

在 Firefox 中删除额外的按钮间距/填充

CSS - 悬停穿过元素以激活悬停在被覆盖的元素上

更改 FontAwesome 图标的字体粗细?

我应该使用最大设备宽度还是最大宽度?

通过 JavaScript 更改 CSS 伪元素样式

使用 CSS 更改
高度

CSS3 过渡:过渡:全部是否比过渡:x慢?

仅针对使用的类优化 Font Awesome

CSS(webkit):在绝对定位元素上用底部覆盖顶部