和光
2016-03-30 15:24
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{padding:0;margin:0}
div{width:200px;
height:80px;
background:#FF3;
/*filter:alpha(opacity:30);*/
opacity:0.3;
margin:20px 0;
}
</style>
<script type="text/javascript">
window.onload=function(){
var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
div1.onmouseover=function(){
startMove(div1,{width:400,height:160})
}
div1.onmouseout=function(){
startMove(div1,{width:200,height:80})
}
}
/*var exm =document.getElementsByTagName('div');
for(var i=0;i<exm.length;i++)
{
exm[i].timer=null;
exm[i].onmouseover=function(){
startMove(this,'width',400);}
exm[i].onmouseout=function(){
startMove(this,'width',200);}
}
}*/
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];}
else
{return getComputedStyle(obj,false)[attr];}
}
function startMove(obj,json){
clearInterval(obj.timer);
var iCur=parseInt(getStyle(obj,attr));
obj.timer=setInterval(function(){
for(var attr in json){
var speed=0;
if(json[attr]>iCur)
{speed=Math.ceil((json[attr]-iCur)/8);}
else if(json[attr]<iCur)
{speed=Math.floor((json[attr]-iCur)/8);}
if(iCur==json[attr])
{clearInterval(obj.timer);}
else
{obj.style[attr]=iCur+speed+'px';}
}
},30)
}
</script>
</head>
<body>
<div id="div1">
</div>
<div id="div2">
</div>
<div id="div3">
</div>
</body>
</html>
把 var iCur=parseInt(getStyle(obj,attr)); 放在for循环里试试
你的attr是在for循环里定义的
没有定义,肯定报错啊
var iCur=parseInt(getStyle(obj,attr));的attr哪里来的
JS动画效果
113923 学习 · 1443 问题
相似问题