0
是否可以通过CSS创建一个只带有SVG路径的动画?获取像SVG动画路径的CSS动画
CSS
html, body {
margin: 0;
height: 100%;
}
svg {
display: block;
position: absolute;
width: 90%;
height: 90%;
top: 5%;
left: 5%;
}
.path {
animation: dash 10s linear infinite;
}
@-webkit-keyframes dash {
to {
stroke-dashoffset: 0;
}
}
HTML
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 659 522" enable-background="new 0 0 659 522" xml:space="preserve" preserveAspectRatio="none">
<path class="path" width="100%" height="100%" fill="none" stroke="#00ff00" stroke-width="5" stroke-miterlimit="10" d="M656.5,2.5v517H2.5V2.5H656.5z" stroke-dasharray="2042 300" stroke-dashoffset="2342" vector-effect="non-scaling-stroke" />
</svg>
这里是fiddle
不,因为CSS不支持此属性或者对其元素具有任何等同属性。另外,您正在使用'@ -webkit-keyframes',但只是一个'animation'属性,这对我来说不起作用。 – somethinghere
我的意思是,而不是使用SVG路径,只用CSS创建它 – AC3
而我的意思是,CSS没有这种选择,也没有什么好的方法来模仿它。笔画是完整的,并且在CSS中没有偏移量,因此您不能在带有标准HTML元素的CSS中执行此操作,只能使用SVG。不要误解我的意思,你可能会用多个元素和嵌套来伪造它,但我认为你的SVG解决方案可能是你想要的效果的最佳选择。 – somethinghere