- 1
how do i make the box move in a other direction?
3 Respostas
+ 3
@Dr_Donko89 suggestion is to rather use Css to animate an element: I'm totally agree that should be done everytime where it's possible, but for asking more accuratly to your question, we need to answer you in a JS context ;)
You're using 'left' property-attribute of a positionned element in your actual code...
> change the sign of the value will revert the position symetrically to the origin, so increasing value will move to the rigth, decreasing will move to the left
> change the property used will change the axis: using 'top' instead 'left' will position on the y-axis, increasing value move to bottom, decreasing move to top
> you can also use (but avoid mix with same axis origin, else this will define size of element on this axis) 'right' and 'bottom', instead 'left' and 'bottom' (or obviously 'right' and 'top', or even 'left' and 'bottom'). As the origin is moved, the logical is inverted: increasing value for 'right' will move to left, for 'bottom' will move to top...
All these logics is still correct in pure Css context, as in JS you just handle values of Css properties in that kind of case ^^
+ 2
https://code.sololearn.com/WJ7BOOUipB30/?ref=app Take a look a my version and learn!
0
change.the initial position, change the x / axis velocity