JavaScript Timer实现动画效果

 <style type="text/css">
div {
width: 100px;
height: 50px;
background: red;
margin: 10px;
}
</style>
<body>
<div></div>
<div></div>
<div></div>
</body>
<script type="text/javascript">
window.onload = function () {
var aDiv = document.getElementsByTagName('div');
for (var i = ; i < aDiv.length; i++) {
aDiv[i].timer=null;
aDiv[i].onmouseover = function () {
startMove(this, );
};
aDiv[i].onmouseout = function () {
startMove(this, );
};
}
} function startMove(obj, iTarget) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var speed = (iTarget - obj.offsetWidth) / ;
speed = speed > ? Math.ceil(speed) : Math.floor(speed);
if (obj.offsetWidth == iTarget) {
clearInterval(obj.timer);
} else {
obj.style.width = obj.offsetWidth + speed + 'px';
}
}, );
}
</script>
上一篇:compileSdkVersion,minSdkVersion 和 targetSdkVersion


下一篇:FastDFS问题汇总