码迷,mamicode.com
首页 > 其他好文 > 详细

关于多物体缓冲运动

时间:2016-04-10 22:41:27      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多物体缓冲运动</title>
</head>
<style>
*{margin:0px;padding:0px;}
#move li{width:200px;height:100px;display:block;margin-bottom:20px;background:yellow;list-style:none;}
</style>
<script>
window.onload=function(){
var oul=document.getElementById(‘move‘);
var ali=oul.getElementsByTagName(‘li‘);
var timer=null
for(var i=0;i<ali.length;i++){
ali[i].onmouseover=function(){
startMove(this,400);
}
ali[i].onmouseout=function(){
startMove(this,200);
}
}
function startMove(obj,itarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(itarget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==itarget){
clearInterval(obj.timer);
}else{
obj.style.width=obj.offsetWidth+speed+‘px‘;
}
},30)

}
}
</script>
<body>
<ul id="move">
<li></li>
<li></li>
<li></li>
</ul>


</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多物体缓冲运动</title>
</head>
<style>
*{margin:0px;padding:0px;}
#move li{width:200px;height:100px;display:block;margin-bottom:20px;background:yellow;list-style:none;}
</style>
<script>
window.onload=function(){
var oul=document.getElementById(‘move‘);
var ali=oul.getElementsByTagName(‘li‘);
var timer=null
for(var i=0;i<ali.length;i++){
ali[i].onmouseover=function(){
startMove(this,400);
}
ali[i].onmouseout=function(){
startMove(this,200);
}
}
function startMove(obj,itarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(itarget-obj.offsetWidth)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==itarget){
clearInterval(obj.timer);
}else{
obj.style.width=obj.offsetWidth+speed+‘px‘;
}
},30)

}
}
</script>
<body>
<ul id="move">
<li></li>
<li></li>
<li></li>
</ul>


</body>
</html>

关于多物体缓冲运动

标签:

原文地址:http://www.cnblogs.com/dingliang/p/5376306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!