- #dv1{
- width:1000px;
- height:1000px;
- overflow:hidden;
- display:none;
- }
- window.onload =function () {
- document.getElementById('btn2').onclick =function () {
- //1启动计时器
- varinter= setInterval(function () {
- //2获取要操作的层
- vardvobj = document.getElementById('dv1');
- //3高度递减
- varh = dvobj.offsetHeight;
- h -= 3;
- if(h <= 0) {
- h = 0;
- //4把新的高度设置给层dvobj.style.height = h + 'px';
- dvobj.style.display = 'none';
- clearInterval(inter);
- } else {
- dvobj.style.height = h + 'px';
- }
- },100)
- }
- document.getElementById('btn1').onclick =function () {
- vardvobj = document.getElementById('dv1');
- if(dvobj.style.display.length==0){
- dvobj.style.display = 'none';
- this.value = '显示';
- } else {
- dvobj.style.display = '';
- this.value = '隐藏';
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2128888.html