function play() {
setTimeout(function(){
if(indexNow == aLi.length) {
indexNow = 0;
}
startMove(aLi[indexNow], {'left': '-800'}, 'easeOut', function(){
console.log(indexNow);
aLi[indexNow].style.left = '800px';
});
startMove(aLi[indexNow + 1], {'left': 0}, 'easeOut');
// console.log('index:' + indexNow);
indexNow ++ ;
}, 3000);
var timer = setTimeout(play, 3000);
}
以这段为例,讲讲各个函数的执行顺序,搞不清异步到底是个什么机制,求大神讲解,给出其他的例子也行谢谢
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
三言两语说不清, 推荐看这篇
JavaScript 运行机制详解:再谈Event Loop 标注版
play执行
3s后
匿名函数执行(开始动画)
play执行
3s后
匿名函数执行(开始动画,若此时上次动画还未结束,此动画会加入动画队列中,等上次动画完成后再开始)
play执行
......