html - 如何动画圆形虚线边框?

标签 html css animation svg

我有一种情况,我必须制作一个虚线边框的半圆形边框。现在我可以为边框设置动画了。

请帮忙

enter image description here

.box{
	height:90px;
	width: 500px;
	background: #ffb08f;
	border-radius:  0 0 30px 30px;
	border: 1px dashed #000;
	border-top:none;
}
<div class="box"></div>

最佳答案

感谢您的回答,我得到了解决方案 -

.line-box {
    top:10px;
    left: 10px;
    overflow: hidden;
    position: absolute;
    display: block
}

.line-box svg {
    position: relative;
    top: -24px;
}
.path {
  animation: dash 20s linear  infinite;
  -moz-animation: dash 20s linear  infinite;
  -webkit-animation: dash 20s linear  infinite;
  -o-animation: dash 20s linear  infinite;
  -ms-animation: dash 20s linear  infinite;
}


@keyframes dash {
  from {stroke-dashoffset: 0;}
  to {stroke-dashoffset: 2000;}
}
@-moz-keyframes dash {
  from {stroke-dashoffset: 0;}
  to {stroke-dashoffset: 2000;}
}
@-webkit-keyframes dash {
  from {stroke-dashoffset: 0;}
  to {stroke-dashoffset: 2000;}
}
@-o-keyframes dash {
  from {stroke-dashoffset: 0;}
  to {stroke-dashoffset: 2000;}
}
@-ms-keyframes dash {
  from {stroke-dashoffset: 0;}
  to {stroke-dashoffset: 2000;}
}
<div class="line-box">
 <svg height="70" width="400">
  <path d="M167,1 h181 a20,20 0 0 1 20,20 v27 a20,20 0 0 1 -20,20 h-50 a20,20 0 0 1 -20,-20 v-27 a20,20 0 0 1 20,-20 z" fill="#ffb08f" stroke="#fff" stroke-width="1"/>
  <path stroke-dasharray="6,6" d="M167,1 h181 a20,20 0 0 1 20,20 v27 a20,20 0 0 1 -20,20 h-50 a20,20 0 0 1 -20,-20 v-27 a20,20 0 0 1 20,-20 z" fill="#ffb08f" stroke="#000" stroke-width="1" class="path"/>

  <path d="M21,2 h273 a20,20 0 0 1 20,20 v27 a20,20 0 0 1 -20,20 h-271 a20,20 0 0 1 -20,-20 v-27 a20,20 0 0 1 20,-20 z" fill="#ffb08f" stroke="#fff" stroke-width="1"/>
  <path stroke-dasharray="6,6" d="M21,2 h273 a20,20 0 0 1 20,20 v27 a20,20 0 0 1 -20,20 h-271 a20,20 0 0 1 -20,-20 v-27 a20,20 0 0 1 20,-20 z" fill="#ffb08f" stroke="#000" stroke-width="1" class="path"/>
 </svg> 
</div>

关于html - 如何动画圆形虚线边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39572865/

相关文章:

css - 动画后 SVG 路径变化

HTML1514 : Extra "<body>" tag found

html - 使用::before 创建围绕圆的线

javascript - 生成动态 HTML 时正确转义字符

css - @font-face 在 Visual Studio 中无法识别

html - 如果选中单选按钮则显示 div

android - JSoup 解析 : get next element

javascript - 两个部分彼此重叠

移除上面的元素后,CSS3 将元素设置为动画或过渡

.net - WinRT 动画不显示中间值