Home > Web Front-end > JS Tutorial > Implement animation effects with JavaScript

Implement animation effects with JavaScript

高洛峰
Release: 2016-11-25 11:28:49
Original
954 people have browsed it

Everyone is using the timeline function in Dreamweaver to create interesting animation effects. Dreamweaver will automatically generate specific program codes for users. Have you ever thought about the implementation principle of animation? In fact, the principle is very simple, mainly using a timer function. Below I will demonstrate a simple animation production process for you. Through the relevant introduction, you can draw inferences and create more dazzling animation effects.

 The effect of this example is that if you click the "Start Moving" button on the web page, the specified layer will move from left to right. During this process, if you click the "Stop Moving" button, it will stop moving.

 

 

 JavaScript Motion Sample

 startMove()

 {

  var left = eval(div1.style.left.replace("px", ""));
  if (left < document.body.scrollWidth - 150)
  div1.style.left = left + 1;

 else

 div1.style.left = 10;
 movingID = setTimeout("startMove()", 10);
 }

 function stopMove()
 {
 clearTimeout(movingID);
  }
 


 
 

 
 

 


 
I can moving...

 


 ;
 

  
 , interval) function, the parameter format of this function is:

The first parameter "function" is the function name to be called after timeout, and the second parameter "interval" is the timeout value in microseconds.


 One thing to note is that if you want to stop this timer, you must save the return value after calling the setTimeout() function, and cancel the timer through the clearTimeout(id) function.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template