下面这段代码就是我按照前面讲的写出来的,但是在引用升序的地方报错了,求解
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{padding: 0;margin: 0;}
div{
width: 200px;
height: 200px;
background: red;
border:10px solid black;
/*font-size:12px;*/
color: white;
filter:alpha(opacity:30);
opacity:0.3;}
</style>
<script>
window.onload=function(){
var div=document.getElementById('div1');
// div.onmouseover=function(){
// move(this,'width',400,function(){
// move(div,'height',400,function(){
// move(div,'opacity',100);
// });//这个地方的div改为this会报错
// });
// }
// div.onmouseout=function(){
// move(this,'opacity',30,function(){
// move(div,'height',200,function(){
// move(div,'width',200);
// });
// });
// }
div.onmouseover=function(){
move(this,{width:400px,height:400px});
}
}
var alpha=30;
function move(obj,json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for(var attr in json){
var icur=0;
if(attr=='opacity'){
icur=Math.round(parseFloat(getstyle(obj,attr))*100);
}else{
icur=parseInt(getstyle(obj,attr));
}
var speed=(json[attr]-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==json[attr]){
clearInterval(obj.timer);
if(fn){
fn();
}
}
else{
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(icur+speed)+')';
obj.style.opacity=(icur+speed)/100;
}else{
obj.style[attr]=icur+speed+'px';
}
}
}
},50);
}
function getstyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
</script>
</head>
<body>
<div id="div1" ></div>
</body>
</html>