Animating with JavaScript

Source: Internet
Author: User
JavaScript in the use of Dreamweaver in the timeline function or to make a very interesting animation effect, Dreamweaver will automatically generate specific program code for users, have you ever thought of the implementation of the principle of animation? In fact, the principle is very simple, mainly using a timer function, below I for everyone

Demo a simple animation production process, through the relevant introduction, we can extrapolate, make more dazzling animation effect.

The effect of this example is to click on the "Start Move" button on the page, then the specified layer will move from left to right, in the process you click the "Stop Moving" button will stop moving.

<title>javascript Motion sample</title>

<script language= "JavaScript" >
var movingid = null;
var scrolling = false;

function 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);
}
</script>

<body>
<div id= "Div1" style= "visibility:visible; Position:absolute; Left:10; Top:10; z-index:1; " >
<table bgcolor= "#FFFFCC" border= "1" cellpadding= "0" cellspacing= "0" >
<tr>
<td>i can moving...</td>
</tr>
</table>
</div>

<br><br>
<input type= "button" value= "Start Moving" >
<input type= "button" value= "Stop Moving" >

</body>

A function called settimeout (function, interval) is used here, and the parameter format of this function is:
The first parameter "function" is the name of the function called after the timeout, and the second argument "interval" is the time-out value, in microseconds.

Note that if you want to stop this timer, you must save the return value after calling this settimeout () function and cancel the timer by cleartimeout (ID) function.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.