html代码:
1 <div width=100%> 2 <img id="gg" src="img/ad.jpg" width="100%" style="display: none;"> 3 </div>
JS代码:
1 //设置定时操作 2 function init(){ 3 time=setInterval("n_b()",3000); 4 5 } 6 //实现none->block 7 function n_b(){ 8 ggEle= document.getElementById("gg"); 9 ggEle.style.display="block"; 10 clearInterval(time); 11 time=setInterval("b_n()",5000); 12 } 13 //实现b->n 14 function b_n(){ 15 ggEle.style.display="none"; 16 clearInterval(time); 17 } 18 window.onload=function(){ 19 init(); 20 }