【发布时间】:2018-10-13 00:05:03
【问题描述】:
我有一个 SVG 线条路径,使用我找到的这个示例进行动画处理:
svg {
position: absolute;
width: 100%;
height: 100%;
left: 0%;
top: 0%;
display: block;
background: transparent;
}
.path {
stroke: black;
stroke-dasharray: 290;
stroke-dashoffset: 130;
animation: dash 6s 0s forwards infinite;
stroke-width: 2px;
stroke-linecap: round;
stroke-linejoin: round;
}
@keyframes dash {
from {
stroke-dashoffset: 290;
}
to {
stroke-dashoffset: 0;
}
}
<svg viewbox="0 0 25 100" xmlns="http://www.w3.org/2000/svg">
<path class="path" d="M0 50 L 12 50, 12 0, 25 0" fill="transparent"></path>
</svg>
它工作正常,但在页面加载时触发。有没有办法(比如说用一个按钮)使用 JavaScript 触发这个动画?
我可以处理 JS,但我是 CSS 和 SVG 动画的菜鸟。
谁能给我一个例子,说明我如何使用我的实际 CSS 做到这一点?
【问题讨论】:
标签: javascript css svg