最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生js實現(xiàn)網(wǎng)頁頂部自動下拉/收縮廣告效果

 更新時間:2017年01月20日 14:58:47   作者:夏天不做夢  
本文主要介紹了原生js實現(xiàn)網(wǎng)頁頂部自動下拉/收縮廣告效果的實例代碼。具有一定的參考價值,下面跟著小編一起來看下吧

知識要點

1.實現(xiàn)原理:

通過遞歸改變div的高度值達到緩慢下拉的效果。

2.一共分為3個步驟我寫了三個函數(shù)

第一個show()函數(shù)(下拉):初始值高度h<300的話 h+5  反之return退出停止,調(diào)用setTimeout方法30毫秒執(zhí)行一次+5

第二個hide()函數(shù)(收回):只是高度的判斷不同高度h-5 反之return退出停止,調(diào)用setTimeout方法30毫秒執(zhí)行一次-5

第三個dd()函數(shù)(再次彈出):這里要注意的是第二次彈出的div是一個新的div把它的高度設(shè)置為0,實現(xiàn)原理與第一個函數(shù)一樣,

并且一定要在第二個函數(shù)(收回)執(zhí)行后再執(zhí)行

完整代碼

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demo</title>
<style>
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;}
h1,h2,h3,h4,h5,h6{font-size:100%;}
address,cite,dfn,em,var{font-style:normal;}
code,kbd,pre,samp{font-family:courier new,courier,monospace;}
ul,ol{list-style:none;}
a{text-decoration:none;}
a:hover{text-decoration:none;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
legend{color:#000;}
fieldset,img{border:0;}
button,input,select,textarea{font-size:100%;}
table{border-collapse:collapse;border-spacing:0;}
.clear{clear: both;float: none;height: 0;overflow: hidden;}
#container{width: 600px; margin: 0 auto;}
p{ line-height: 28px; }
.hidden{background: #E6E6E6; text-align: center; height: auto; overflow: hidden;}
.show{ background: #808080;text-align: center; height: 0; overflow: hidden; }
</style> 
</head> 
<body>
 <div id="container">
  <div class="hidden" id="hid"><p>廣告圖</p></div>
  <div class="show" id="sho"><p>哈哈哈哈改裝成功</p></div>
 </div>
 <script type="text/javascript"> 
 window.onload=function aa(){
 show();
 setTimeout("hide()",3000);
 }
 var h=0;
 var hid=document.getElementById("hid");
 var sho=document.getElementById("sho");
 function show(){
 if(h<300){
  h+=5;
  hid.style.height=h+"px";
 }else{
  return;
 }
 setTimeout("show()",30);
 } 
 function hide(){
 if(h>0){
  h-=5;
  hid.style.height=h+"px";
 }else{
  dd();
  return;
 }
 setTimeout("hide()", 30);
 }
 var a=0;
 function dd(){
 if(a<60){
  a+=1;
  sho.style.height=a+"px";
 }else{
  return;
 }
 setTimeout("dd()",30);
 }
 </script>
</body> 
</html> 

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論

连南| 商水县| 牟定县| 乌审旗| 都昌县| 肇庆市| 勃利县| 丰宁| 永年县| 华坪县| 阜宁县| 博乐市| 宜宾县| 大城县| 原阳县| 晋宁县| 新平| 嫩江县| 屯昌县| 托克逊县| 哈密市| 淄博市| 郧西县| 东莞市| 临朐县| 汝南县| 鄢陵县| 星子县| 晋城| 大埔区| 麟游县| 衡东县| 明溪县| 商河县| 龙井市| 科技| 延津县| 库伦旗| 茂名市| 鄂温| 莆田市|