<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
</head>
<body>
<style type="text/css">
#div1 {
width: 300px;
height: 600px;
border: 1px solid red;
overflow: hidden;
background-color:aquamarine;
}
</style>
<input type="button" id="btn1" value="隐藏"/>
<div id="div1">
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<h1>溢出隐藏</h1>
<input type="text" />
<input type="radio" />
<input type="button" value="按钮" />
<input type="text" />
<input type="radio" />
<input type="button" value="按钮" />
</div>
<script type="text/javascript">
var height = document.getElementById('div1').offsetHeight;
window.onload = function () {
document.getElementById('btn1').onclick = function () {
if (document.getElementById('div1').style.display == '') {
var intervalID = setInterval(function () {
var currentHeight = document.getElementById('div1').offsetHeight;
currentHeight -= 6;
if (currentHeight > 0) {
document.getElementById('div1').style.height = currentHeight + 'px';
}
else {
document.getElementById('div1').style.display = 'none';
clearInterval(intervalID);
document.getElementById('btn1').value = '显示';
}
}, 0.5);
}
else {
this.value = '隐藏';
var divObj = document.getElementById('div1');
divObj.style.display = '';
var startHeight =1;
var intervalID2 = setInterval(function () {
startHeight += 6;
if (startHeight < height) {
divObj.style.height = startHeight + 'px';
}
else {
divObj.style.height = startHeight + 'px';
clearInterval(intervalID2);
}
}, 1);
}
};
};
</script>
</body>
</html>