为什么我按照老师写的程序,在chrome和IE上面宽度和高度只能变化到393呢?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>任意值运动</title>
<style>
body{
margin:0;
padding:0;
}
div{
width:200px;
height:200px;
background: green;
margin:50px;
font-size:10px;
}
</style>
<script>
window.onload = function () {
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var oDiv3 = document.getElementById('div3');
oDiv1.onmouseover = function () {
startMove(this,'height',400);
};
oDiv1.onmouseout = function () {
startMove(this,'height',200);
};
oDiv2.onmouseover = function () {
startMove(this,'width',400);
};
oDiv2.onmouseout = function () {
startMove(this,'width',200);
};
oDiv3.onmouseover = function () {
startMove(this,'fontSize',50);
};
oDiv3.onmouseout = function () {
startMove(this,'fontSize',10);
};
} ;
var iCount = 0;
function startMove(obj,attr,iTarget) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var iCur = parseInt(getStyle(obj,attr));
var speed = (iTarget - iCur) / 8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if(iCur == iTarget){
clearInterval(obj.timer);
}else{
obj.style[attr] = iCur + speed +'px';
}
},30);
}
function getStyle(obj, attr) {
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
</script>
</head>
<body>
<div id = 'div1'></div>
<div id = 'div2'></div>
<div id = 'div3'>hello world</div>
</body>
</html>