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