<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>动画</title>
<style>
body{
margin:0;
padding:0;
}
ul,li{
list-style:none;
}
ul li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px;
border:4px solid #000;
}
</style>
<script type="text/javascript">
window.οnlοad=function(){
var Li1=document.getElementById('li1');
var Li2=document.getElementById('li2');
Li1.οnmοuseοver=function(){
startMove(this,'height',400);
}
Li1.οnmοuseοut=function(){
startMove(this,'height',100);
}
Li2.οnmοuseοver=function(){
startMove(this,'width',400);
}
Li2.οnmοuseοut=function(){
startMove(this,'width',200);
}
}
function startMove(obj,attr,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var icur=parseInt(getStyle(obj,attr));
var speed=(iTarget-icur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){
clearInterval(obj.timer);
}else{
//alert(getStyle(obj,'width'));
obj.style[attr]=icur+speed+"px";
}
},30);
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr]; //IE
}else{
return getComputedStyle(obj,false)[attr]; //火狐
}
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
<li id="li2"></li>
</ul>
</body>
</html>
js多物体不同运动
最新推荐文章于 2019-02-11 15:14:07 发布