How to animate using javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to animate using javascript?

So I have been trying to figure out how to animate an image on click of a button, for example if the user clicked a button, an image would move from the left side to the right side of the screen and then stop. Any help is always appreciated! 😃

10th Apr 2017, 5:07 PM
iBrandon
iBrandon - avatar
4 Answers
+ 13
I hope this code might help you https://code.sololearn.com/WCHWEkTQqriI/?ref=app
10th Apr 2017, 5:31 PM
Gami
Gami - avatar
+ 7
at Khan academy the coding animation tutorial is really goid
10th Apr 2017, 8:22 PM
Theprogrammers
Theprogrammers - avatar
+ 3
You can have transition property on img like this img{ transition: 2s; transition-timing-function: linear; position: relative; left:0 } <button onclick="move()">Move Image</button> <script> function move(){ var img = document.getElementsByTagName('img')[0]; img.style.left= '100px'; //whatever you want } </script>
10th Apr 2017, 5:16 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 2
You also can use javascript libraries such as jQuery or Greensock, especially Greensock, they are better and easier for this kind of purpose.
10th Apr 2017, 5:18 PM
Geoffrey L
Geoffrey L - avatar