Raphael js,沿路径问题制作动画
我定义了两个圆和一条路径,其中路径连接两个圆的中心点:
c1=r.circle(40, 40, 20).attr(dashed);
c2=r.circle(140, 40, 20).attr(dashed);
path = r.path("m 40 40 l 100 0");
我希望具有这样的功能,当鼠标单击路径线上时,左圆 c1
将折叠右圆c2
(即左圆c1
将移动到并最终加入右圆c2
),在此过程中,< strong>路径总是连接两个圆的中心点,即随着两个圆越来越近,路径会越来越短。
我不知道如何实现这个功能,我尝试了类似的东西
path.onclicke(){
c1.animateAlong(path, 1000, true, function (){
c1.attr({cx: 140, cy: 40});
});
}
,但我不知道如何处理路径,因此随着 c1 越来越接近 c2,路径变得越来越短。有人可以帮忙吗?
I have defined two circles and one path, where the path connect the center points of two circles:
c1=r.circle(40, 40, 20).attr(dashed);
c2=r.circle(140, 40, 20).attr(dashed);
path = r.path("m 40 40 l 100 0");
I would like to have the feature that when mouse click on the path line, the left circle c1
will collapse with the right circle c2
(that's the left circle c1
will move to and finally join the right circle c2
), and during this process, the path will always connect the center points of the two circles, that's the path will get shorter and shorter as two circles get closer.
I am not sure how to implement this feature, I tried some thing like
path.onclicke(){
c1.animateAlong(path, 1000, true, function (){
c1.attr({cx: 140, cy: 40});
});
}
But I don't know how to handle the path, so that the path is getting shorter as c1 get closer to c2. Anyone can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我向你保证,在过去的两周里,我已经完成了与路径的角力。我碰巧注意到路径对象的 .attr() 和 .animate() 可以被赋予一个全新的路径字符串(请参阅
这是你想要的吗?
I've done my share of wrestling with paths in the last two weeks, I assure you. I happened to notice that .attr() and .animate() for path objects can be given an entirely new path string (see the documentation at http://raphaeljs.com/reference.html#Element.attr). So, I mocked up your example in horrible day-glo colors and got the results I think you're looking for like this:
Is this what you had in mind?