我正在尝试使用javascript构建led动画。目前,我可以通过以下方式获取错误:http://jsbin.com/esakip/1/

动画parten:

* ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___ * ___

它每400ms显示一次,我希望它像这样切换:

打开/关闭3次,然后睡眠1秒钟,然后再次执行此过程。

* _ * _ * ______ * _ * _ * ______ * _ * _ * ______ * _ * _ * ______ * _ * _ * ______

最佳答案

使其可配置:

var pattern=('*_*_*______').split('');

function showNext(lastIndex){
    var nextIndex = lastIndex+1;
    // go back to the start if we are past the end
    nextIndex = nextIndex % pattern.length;
    // do we need to do anything?
    if(pattern[lastIndex] != pattern[nextIndex]){
        //fade in or out depending on the current symbol
        if(pattern[nextIndex]=='*'){
            $('#led').fadeIn('fast');
        }else{
            $('#led').fadeOut('fast');
        }
    }
    // call this function again after a pause
    setTimeout(function(){showNext(nextIndex);},400);
}
// start the thing off
showNext(-1);

关于javascript - 如何实现这样的led动画?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15922206/

10-11 06:59