<script>
window.onload = function() {
var oAd = document.getElementById('ad');
var oAction = document.getElementById('action');
var h = 0;
var maxH = oAction.height;
console.log(maxH);
var timer;
var step = 5; //变化程度都一样的
function adDrop() {
oAd.style.height = h + 'px';
oAd.style.display = 'block';
if( h < maxH){
h += step;
// oAd.style.height = h + 'px';
// oAd.style.display = 'block';
setInterval(adDrop, 500);
}
else {
// oAd.style.height = h + 'px';
// oAd.style.display = 'block';
setTimeout(adUp, 2000);
}
}
function adUp() {
if(h>0){ //有值时,已经判断过h 是》 = maxH
h -= step;
oAd.style.height = h + 'px';
oAd.style.display = 'none'
setInterval(adUp, 1);
}
}
setTimeout(adDrop, 2000);
}
</script>
</head>
<body>
<div id="ad"><img src="img/1.jpg" alt="" id="action" ></div>
<div class="content">网页内容</div>
</body>