Multi-object motion for switching

Source: Internet
Author: User

The above article briefly indicates a multi-object fade-in, mainly to grasp the timer usage and parameters and speed of processing, this article describes the movement of multiple objects, and the movement of a single object a little different.

Here are some brief codes to write:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<title></title>
<style type= "Text/css" >
div {width:100px;height:50px;background:red;margin-top:30px; border:3px solid black;}
</style>
<script type= "Text/javascript" >
Window.onload = function () {

var odiv = document.getelementsbytagname (' div ');
var i=0;
for (i=0;i<odiv.length;i++) {
Odiv[i].timer = null; Set multiple timers, give the timer an index value
Odiv[i].onmouseover = function () {
Setmove (this,300); Add a style to the current Div, and the next parameter is the target value to set
}
Odiv[i].onmouseout = function () {
Setmove (this,100);
}
}
};

function Setmove (obj,itarget) {//Set multiple parameters
var timer = null;
Clearinterval (Obj.timer); Turn off the current timer before turning on the timer
Obj.timer = setinterval (function () {//Set timer for current Div

var ispeed = (itarget-obj.offsetwidth)/8;
Ispeed=ispeed>0?      Math.ceil (ispeed): Math.floor (Ispeed); Converts the current speed into an integer value
Math.ceil rounding up, Math.floor downward rounding
if (obj.offsetwidth==itarget) {
Clearinterval (Obj.timer);//Clear the current Div's timer
}else{
Obj.style.width =obj.offsetwidth+ispeed+ ' px '; Increase the width of the div at a certain speed
}
},30);
}
</script>
<body>
<div></div>
<div></div>
<div></div>
</body>

Of course, the movement here, the form of exercise is relatively single, only for width or height, and does not implement multiple forms of movement, here will be a brief introduction

Multi-object motion for switching

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.