abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/14/2020

How to create JavaScript animation - moving image

 in this below example move image from original position to right.

we use setTimeout and clearTimeout to start and stop image animate.


html input button click method handle.


<script type = "text/javascript">

 

var getimage = null;

var animate ;

function init() {

   getimage = document.getElementById('myImage');

   getimage.style.position= 'relative'; 

   getimage.style.left = '0px'; 

}

function move() {

   getimage.style.left = parseInt(getimage.style.left) + 10 + 'px';

   animate = setTimeout(move,60);    // call move in 60msec

}

function stop() {

   clearTimeout(animate);

   getimage.style.left = '0px'; 

}

window.onload = init;

 

</script>

<div>

 <img id = "myImage" src = "hello.png" />

 <p>Click the buttons below to handle animation</p>

 <input type = "button" value = "Start" onclick = "move()" />

 <input type = "button" value = "Stop" onclick = "stop()" />

</div>      


please comment your query.

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...