如果我理解正确,可以通过将动画相关代码放在函数中并在每个动画结束时调用该函数来实现:
function cycle() {
this.stroke({width: 0, opacity: 1})
.animate(1000, '>', 800)
.stroke({opacity:0, width: 34})
.after(cycle);
}
那我们就可以用
cycle.apply(foreground)
得到
this
要转换元素并启动动画,请执行以下操作:
var draw = SVG('content').size(500, 300)
var circle = draw.circle(100).attr({ fill: 'steelblue' }).move(200,20)
cycle.apply(circle);
function cycle() {
this.stroke({width: 0, opacity: 1})
.animate(1000, '>', 800)
.stroke({opacity:0, width: 34})
.after(cycle);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.5/svg.js"></script>
<div id="content"></div>