<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 200px;
height: 200px;
background-color: red;
position: absolute;
left: 0px;
top: 100px;
}
</style>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="box"></div>
</body>
<script type="text/javascript">
window.onload = function(){
var box = document.getElementById("box");
var s = null;
box.onmouseover= function(){
startMove(600)
}
box.onmouseout = function(){
startMove(200)
}
}
function startMove(giao){
clearInterval(s);
var speed = 0;
s = setInterval(function(){
if(box.offsetHeight < giao){
speed = 10;
}else{
speed = -10;
}
if(box.offsetHeight == giao){
clearInterval(s);
}else{
box.style.height = box.offsetHeight + speed + "px";
}
},50)
}
</script>
</html>
<html>
<head>
<style>
#box {
width: 200px;
height: 200px;
background-color: red;
position: absolute;
left: 0px;
top: 100px;
}
</style>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="box"></div>
</body>
<script type="text/javascript">
window.onload = function(){
var box = document.getElementById("box");
var s = null;
box.onmouseover= function(){
startMove(600)
}
box.onmouseout = function(){
startMove(200)
}
}
function startMove(giao){
clearInterval(s);
var speed = 0;
s = setInterval(function(){
if(box.offsetHeight < giao){
speed = 10;
}else{
speed = -10;
}
if(box.offsetHeight == giao){
clearInterval(s);
}else{
box.style.height = box.offsetHeight + speed + "px";
}
},50)
}
</script>
</html>