Raphael JS:如何移动/动画路径对象? [英] Raphael JS : how to move/animate a path object?

查看:28
本文介绍了Raphael JS:如何移动/动画路径对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故这不起作用...

Somehow this doesn't work...

var paper = Raphael("test", 500, 500);

var testpath = paper.path('M100 100L190 190');

var a = paper.rect(0,0,10,10);
a.attr('fill', 'silver');

a.mousedown( function() {
  testpath.animate({x: 400}, 1000);
});

我可以通过这种方式移动矩形,但不能移动路径,为什么会这样,然后我如何移动路径对象?!

I can move rects this way but not paths, why is that, and how do I move a path object then?!

推荐答案

使用最新版本的 Raphael,您可以这样做:

With the latest version of Raphael, you can do this:

var _transformedPath = Raphael.transformPath('M100 100L190 190', 'T400,0');
testpath.animate({path: _transformedPath}, 1000);

这使您免于必须克隆临时对象的麻烦.

This saves you from the trouble of having to clone a temp object.

这篇关于Raphael JS:如何移动/动画路径对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆