+1

How can I make the small square box move to the left

My js animation is not working. After the small box moves to the right and down, it refuses to move to the left. What is wrong? https://code.sololearn.com/W5wObr7tsIh1/?ref=app

3/23/2020 3:26:46 PM

Fasasi Sherif

7 Answers

New Answer

+3

This also works: var pos3 = 150; function move3() { if ( pos3 <= 0){ clearInterval(t); } else { pos3 -= 1; inside[0].style.left = pos3+"px"; } } https://code.sololearn.com/WdEC7l5bq0b7/?ref=app

+1

Good try. Because you are fixing the position with style.left in move1(), don't try to fix position with style.right in move3() Instead, you should still change style.left with pos1 -= 1 in move3() A fix for you: https://code.sololearn.com/Wg9on8H9HnxQ/?ref=app Try same concept for moving up along the left edge in a move4()

+1

Thanks very much . But why does style.right in move3() not work.

+1

The reference point of canvas (x,y) is its left upper corner (0,0). Therefore, the distances between the left and the upper side of a shape was defined (determined) for its position. Thus style.right do not work.

+1

Thanks @BroFar

+1

Thanks @Ja Play

+1

Thanks guys I've completed it. https://code.sololearn.com/Wf1h8H68F2WO/?ref=app