2010-09-03 74 views
9

所以我使用Raphael JS来尝试和animateRaphael JS - animate .text()

这是我已经试过:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
    <script type="text/javascript" src="http://raphaeljs.com/raphael.js"></script> 
    <script type="text/javascript"> 
     $(window).load(function() { 
      var R = Raphael("holder", 640, 480); 
      var test = R.text(200, 200, "Test string"); 
      test.animate({cx: 20, cy: 20}, 2000); 

     }); 
    </script> 
</head> 
    <body> 
     <div id="holder"> 
     </div> 
    </body> 
</html> 

而且我的文字只是保持在200,200。任何想法为什么这不起作用?

回答

5

animate函数仅具有某些属性,并且只能为属于该特定对象的属性制作动画。

文本对象没有cx或cy属性 - 因此您的示例代码不会动画。

您只能翻译文本对象,因为它只有x,y和文本属性。

http://raphaeljs.com/reference.html#text

如果你想翻译文本,使用x和y属性是这样的:

test.animate({x:20, y:20}, 2000); 
+0

感谢@约翰,与移动它{X:20 Y:20}是完全是我需要做的。我没有意识到文字有x/y而不是我正在使用的(cx cy) – Incognito 2010-09-03 16:58:07

+0

太棒了!我担心你正在尝试轮换,然后对我的回答有点失望,嘿嘿。不用谢! – John 2010-09-03 17:03:21