+ 5
how to move these boxes right-left & up-down continuously???
6 Réponses
+ 6
thanks, Calviղ
+ 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
+ 3
JME thanks
+ 3
+ 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
+ 2
Better use style.transform, much faster...