这是我第一次尝试使用 snap.svg 为多边形点设置动画,我觉得我做错了什么。
这是我的代码:
var fdr = Snap('#fdright');
var time1_stp0 = [363.617,262.895, 363.562,367.4, 273.145,315.191, 273.145,315.191];
var time1_stp1 = [363.617,262.895, 363.562,367.4, 273.145,315.191, 273.145,210.688];
var timeline1 = fdr.polygon(time1_stp0).attr({fill:'red',opacity:'0.5'});
timeline1_anim = function(){
timeline1.animate({"points":time1_stp1},3000,mina.linear);
}
timeline1_anim();
页面一加载,我的多边形就消失了(我猜这是因为我的函数在多边形创建后立即被调用)。我检查了 html,我的多边形仍然存在,但这是我得到的:
<polygon fill="#ff0000" style="opacity: 0.5;" points="363.617"></polygon>
我不明白可能是什么问题,所以如果有人得到答案,我会很高兴听到。
编辑:我尝试添加“toString()”,但它仍然不起作用:
timeline1_anim = function(){
timeline1.animate({"points":time1_stp1.toString()},3000,mina.linear);
}
最佳答案
我认为 Snaps 多边形动画中存在错误。它已列出 here从那里链接了一个提交的补丁。
但是,如果需要的话,您可以通过为数组值设置动画来轻松解决这个问题。
timeline1_anim = function(){
Snap.animate(time1_stp0, time1_stp1,
function( val ){
timeline1.attr({ points: val })
},
2000);
}
如果你做了很多,你可以写一个小插件来包含它......
Snap.plugin( function( Snap, Element, Paper, global ) {
Element.prototype.polyAnimate = function( destPoints, duration, easing, callback ) {
var poly = this;
Snap.animate( this.attr('points'), destPoints,
function( val ){ poly.attr({ points: val }) }, duration, easing, callback)
};
});
timeline1.polyAnimate( time1_stp1, 2000, mina.linear, function() { alert('finished')})
关于javascript - 动画多边形点 snap.svg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34991254/