how to move these boxes right-left & up-down continuously??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

how to move these boxes right-left & up-down continuously???

https://code.sololearn.com/W08794udgz49/?ref=app

30th Jul 2020, 7:45 PM
P...
6 Answers
+ 6
thanks, Calviղ
31st Jul 2020, 3:28 AM
P...
+ 4
Step 1. Instead of always adding 1 to pos add a variable so you can set the direction you want it to move Step2. Instead of clearing interval when it goes all the way right, set the direction variable negative
30th Jul 2020, 8:32 PM
JME
+ 3
JME thanks
31st Jul 2020, 3:27 AM
P...
31st Jul 2020, 6:33 PM
P...
+ 2
Step3. Take out animation from if condition, otherwise it won't change direction. Step4. Instead of animate all these boxes, animate container only Step5. Instead of element.style.left, set element.style.top for up down animation https://code.sololearn.com/Wn6i2Ee1Cg7I/?ref=app https://code.sololearn.com/WpV3qgKw7uRR/?ref=app
31st Jul 2020, 1:23 AM
Calviղ
Calviղ - avatar
+ 2
Better use style.transform, much faster...
31st Jul 2020, 3:42 AM
Łukasz Kamiński
Łukasz Kamiński - avatar