顶部广告,代码有问题吗?
为何我将ID放在注释一的位置,就不能成功?
2015-07-27
<div id="ad"> <img id="adcon" src="ad.png" width="960" height="385"/> </div> <div id="content"><img src="数字商品-10-23.jpg" /></div> <script> //全局变量 var oAd = document.getElementById('ad'); var oAdcon = document.getElementById('adcon'); var h = 0; var step = 5; var maxH = oAdcon.height; function adDown(){ oAd.style.height = h +'px'; oAd.style.display = 'block'; if(h<maxH){ h+=step; setTimeout(adDown,1); }else{ setTimeout(adUp,3000); } } function adUp(){ if(h>0){ h-=step; oAd.style.height = h +'px'; setTimeout(adUp,1); } } setTimeout(adDown,3000); </script>
<div id="ad">
<img id="adcon" src="ad.png" width="960" height="385"/>
</div>
<div id="content"><img src="数字商品-10-23.jpg" /></div>
<script>
//全局变量
var oAd = document.getElementById('ad');
var oAdcon = document.getElementById('adcon');
var h = 0;
var step = 5;
var maxH = oAdcon.height;
function adDown(){
oAd.style.height = h +'px';
oAd.style.display = 'block';
if(h<maxH){
h+=step;
setTimeout(adDown,1);
}else{
setTimeout(adUp,3000);
}
}
function adUp(){
if(h>0){
h-=step;
oAd.style.height = h +'px';
setTimeout(adUp,1);
}
}
setTimeout(adDown,3000);
</script>
<div id="ad"> <img id="adcon" src="ad.png" width="960" height="385"/> </div> <div id="content"><img src="数字商品-10-23.jpg" /></div> <script> //全局变量 var oAd = document.getElementById('ad'); var oAdcon = document.getElementById('adcon'); var h = 0; var step = 5; var maxH = oAdcon.height; function adDown(){ oAd.style.height = h +'px'; oAd.style.display = 'block'; if(h<maxH){ h+=step; setTimeout(adDown,1); }else{ setTimeout(adUp,3000); } } function adUp(){ if(h>0){ h-=step; oAd.style.height = h +'px'; setTimeout(adUp,1); } } setTimeout(adDown,3000); </script>
还有个小问题,这是另一段代码,script中依然是外边全局,但这个是可以执行成功的啊?
举报