微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Raphael和Javascript使矢量点闪烁

我正在使用 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.
Parameters

newAttrs 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]

最后一个参数是我们需要的.您只需要分配功能即可在动画完成后调用.

原文地址:https://www.jb51.cc/js/153289.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐