我尝试用javascript构建led动画。臭虫目前我能够得到这样的:http://jsbin.com/esakip/1/如何模仿这样的led动画?
动画parten:
*___*___*___*___*___*___*___*___*___*___*___*___*___*___
它显示每400毫秒,我想将其切换这样的例子:
开/关3次开关,然后睡1秒,然后再做这个过程。
*_*_*______*_*_*______*_*_*______*_*_*______*_*_*______
我尝试用javascript构建led动画。臭虫目前我能够得到这样的:http://jsbin.com/esakip/1/如何模仿这样的led动画?
动画parten:
*___*___*___*___*___*___*___*___*___*___*___*___*___*___
它显示每400毫秒,我想将其切换这样的例子:
开/关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);
使用jQuery:
$('#led').fadeIn('fast').fadeOut('fast').fadeIn('fast').fadeOut('fast').delay('1000').fadeIn('fast').fadeOut('fast').fadeIn('fast').fadeOut('fast').delay('1000');
...
必须这样做:
while (true)
$('#led').fadeIn('fast').fadeOut('fast').fadeIn('fast').fadeOut('fast').delay('1000');
使用而崩溃的浏览器...如果你需要循环这个动画,把它放在一个有趣的地方ction一次又一次回忆吧..
$(function(){
setInterval(function(){
$('#led').fadeIn('fast').fadeOut('fast').fadeIn('fast').fadeOut('fast').delay('1000');
},1800);
});
感谢您example.But如何使这个动画spped可配置?在你的例子中,它在一秒内切换2次。如果我想闪3次。我必须将代码更改为:('#led')。(fadeIn('fast')。 。淡出( '快')延迟( '1000'); – qichunren 2013-04-10 10:08:26
你只需要总结动画时间。快是200毫秒,因此间隔1800毫秒来自200 + 200 + 200 + 200 + 1000毫秒= 1800. http://jsfiddle.net/kvJsc/6/ – elasticman 2013-04-10 10:19:51
你让我崩溃铬... – qichunren 2013-04-10 09:55:12