我正在使用
Raphael JS库,而我正在试图弄清楚如何使屏幕出现,然后消失.
我使用for循环来创建点,然后让它们淡入淡出.有没有办法可以淡出,我可以删除它们?
我对Javascript很新,所以我不知道处理这个的最好的策略.我在拉斐尔文档中看不到如何做到这一点.
<!DOCTYPE html> <html lang="en"> <head> <Meta charset="utf-8"> <title>blink point</title> <script src="js/raphael.js"></script> <!--<script src="https://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js"></script>--> <script type="text/javascript"> window.onload = function () { //Point Array pointList = new Array (); // Create Canvas var r = Raphael(10,50,600,600); // Make a 'group' of points for( i=0; i<20; i++){ //Create Point pointList[i] = r.circle(10*i,10*i,5); pointList[i].attr({stroke: "none",fill: "#999",opacity: 0}); //Fade in pointList[i].animate({opacity: 1},1000 ); } // Remove points,starting with the first for( i=0; i<20; i++){ //Try fading them out //pointList[i].animate({opacity: 0},1000 ); } }; </script> </head> <body> <div id="holder"></div> </body> </html>
我也无法获得Raphael图书馆的在线链接,因此可能需要下载该图书馆.
解决方法
你可以在这里找到工作示例
http://jsbin.com/uxege4/2/edit
详细信息:
详细信息:
您的代码的问题 – 动画是异步完成的,这意味着您的程序将在渐变之前完成.
所以当动画准备就绪时,需要设置回调函数.这是拉斐尔文件的引用:
animate
Changes an attribute from its current value to its specified value in the given amount of milliseconds.
ParametersnewAttrs object A parameters object of the animation results. (Not all attributes can be >animated.)
ms number The duration of the animation,given in milliseconds.
callback function [optional]