Multiple counters in Javascript for loop

后端 未结 3 680
长情又很酷
长情又很酷 2020-12-08 02:50

Before i tear my hair out and go down the wrong path in terms of debugging. Can someone confirm that this code will do as intended. Ie. animate 5 divs to different positions

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 03:19

    You've got some semicolons where you want commas:

    for (i=1, j=0, k=150; i<=5; i++, j+=30, k-=30) { /* do work */ }
    

    You should only have three "statements" inside your for

    for( [init]; [test]; [increments]) { [block] }
    

    To do multiple [inits] or [increments] you have to use the sometimes magical, but oft forgotten, comma operator

提交回复
热议问题