[英]Animate polygon points snap.svg
it's the first time I tried to animate polygon points with snap.svg and I have the felling I'm doing something wrong there. 这是我第一次尝试使用snap.svg设置多边形点的动画,但是当我砍伐时,我在那做错了什么。
Here is my code : 这是我的代码:
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();
As soon as the page is loaded, my polygon disappears (I guess it's because my function is called right after the creation of the polygon). 页面加载后,我的多边形就会消失(我猜是因为创建多边形后立即调用了我的函数)。 I checked the html, my polygon's still there but here is what i get :
我检查了html,我的多边形仍然存在,但是我得到的是:
<polygon fill="#ff0000" style="opacity: 0.5;" points="363.617"></polygon>
I don't get what might be the issue, so if someone's got an answer i'll be glad to hear it. 我不明白这可能是什么问题,因此,如果有人得到了答案,我将很高兴听到它。
EDIT : I tried to add "toString()" but it's still not working : 编辑:我试图添加“ toString()”,但仍无法正常工作:
timeline1_anim = function(){
timeline1.animate({"points":time1_stp1.toString()},3000,mina.linear);
}
I think there's a bug in Snaps polygon animation.. its listed here There is a patch submitted linked from there. 我认为Snaps多边形动画中存在一个错误。. 此处列出了那里提交了一个补丁。
However, you can get around this easily by animating the array values though if needed. 但是,如果需要,可以通过对数组值设置动画来轻松解决此问题。
timeline1_anim = function(){
Snap.animate(time1_stp0, time1_stp1,
function( val ){
timeline1.attr({ points: val })
},
2000);
}
If you are doing a lot of them, you could write a small plugin to include it... 如果您正在做很多事情,则可以编写一个小插件来包含它...
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')})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.