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

查看:886
本文介绍了拉斐尔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);
});

我可以移动rects这种方式而不是路径,这是为什么,以及如何移动路径对象呢?!

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

推荐答案

随着拉斐尔的最新版本,你可以这样做:

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.

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

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