jquery synchronize several events

I have a function that I wanna execute several times for different dom elements, for example element A,B,C, and D. This function is recursive, meaning that when it finishes its execution it runs again, after some timeout, for the same element. Now, I want that element A starts the execution before B,C and D. Also B starts before D and B and so on. I tried the following setTimeout(execute(A),1000); setTimeout(execute(B),2000); setTimeout(execute(C),3000); setTimeout(execute(D),4000); function execute(element){ doSomething(); setTimeout(execute(element),5000); } I don't know if this is correct way of doing it. The problem is that if I set the innitial timeout values all the same, so that they all start at the same time, everything works fine. But if not, like the example above, then sometimes it works, sometimes not, I mean it always works, the problem is that they don't seem to follow the same sequence of time. I see that they start in different points of time but after some seconds, for example there are some already at the same time... Any idea? Thanks

以上就是jquery synchronize several events的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏