為什么沒(méi)有運(yùn)動(dòng)?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type='text/css'>
#div1{
height:100px;
background: red;
width:200px;
color:black;
? ? font-size: 12px;
? ? margin-bottom: 20px;
? ? border: 1px solid black;
}?
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv = Document.getElementById('div1');
oDiv.onmouseover=function(){
? ? ? ? startMove(oDiv,'width',400,function(){
? ? ? ? startMove(oDiv,'height',200);
? ? ? ? });
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//ie瀏覽器內(nèi)核
}else{
return getComputedStyle(obj,false)[attr];//火狐瀏覽器內(nèi)核
}
}
var timer=null;
function startMove(obj,attr,iTarget,fn){
clearInterval(obj.timer);//1.2+++
obj.timer=setInterval(function(){//1.2+++
var icur=0;
icur=parseInt(getStyle(obj,attr));
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){
if(fn){
fn();
}
clearInterval(obj.timer);//1.2+++
}else{
obj.style[attr]=icur+speed+'px';
}
},30);
}
</script>
</head>
<body>
<ul>
<div id='div1'>哈哈</div>
</body>
</html>
2015-11-10
Document不能大寫(xiě),這個(gè)是系統(tǒng)常量不能寫(xiě)錯(cuò)了。