途牛banner自動輪播

<!DOCTYPE html>               <!--申明文檔類型:html-->css

<html lang="en">                <!--html 根標籤 lang:language--en:english--'zh-CN'中文簡體-->html

<head>函數

<meta charset="UTF-8">字體

<meta name=「Generator「 content="Editplus">               <!--字符集:UTF-8BI編碼-->ui

<meta name="Author" content="千尋">                          <!--做者-->this

<meta name="Keywords" content="途牛">                       < --描述-->編碼

<meta name="Desription" content="途牛.......">               <--網頁標題-->url

<title>途牛banner自動輪播</title>htm

<!--css層疊樣式 修飾,美化 網頁-->對象

<style>

*{/*通配符*/

margin:0px;/*外邊距*/

padding:0px;/*內邊距*/

body{backround:url('imges/bg.jpg');       /*背景*/}

#box{

padding:10px;/*內邊距*/

width:100px;/**寬:100像素/

height:100px;/*高*/

border:1px solid red;/*邊框:邊框大小 實線顏色*/} 

margin:100px auto; /*外邊距:頂部距離 自動水平居中*/

position:relative;/*定位:相對定位   參照物*/  

cursor:pointer;

#box img{

position:absolute;

top:0px;

left:0px;

opacity:0;                           /*透明度*/

}

#box img.firstImg{

opacity:1;

 

}

 

 

#box ul{

position:abolute;

list-style:none;      /*列表風格:無*/

border:1px solid red;

left:4px;

bottom:15px;        /**/

}

#box ui li{

background:rgb(255,255,255);

width:119px;

height:30px;

margin:1px;

text-align:center;                /*文字對齊方式:水平居中*/

line-height:30px;                /*行高*/

float:left;                            /*左浮動     向下排列變成向右排列*/

/*rgba(0-255,0-255,0-255,0-1)*/

a-alpha      透明度

      a:0徹底透明

         1徹底不透明

}

#box ul li.firstBtn{

background:rgba(0,0,0,0.7);

color:#fff;

}

 

 

#box p{

height:100px;

width:65px;

background:rgba(0,0,0,0.5);

position:absolute;

color:white;

font-size:70px;/*字體大小*/

text-align:center;

line-height:100px;

top:125;                           /*參考對象的一半*/

#box .btnLeft{

left:10px;

}

#box .btnRight{

right:10px;

}

</style>

<body>                                <!--網頁主體:結構 可視化區域-->

   <div id="box">                   <!---id命名惟一性(身份證)->

 

 

         <img class=firstImg src="images/1.jpg" />

          <img src="images/1.jpg" />

          <img src="images/2.jpg" />

          <img src="images/3.jpg" />

          <img src="images/4.jpg" />

          <img src="images/5.jpg" />

          <img src="images/6.jpg" /> 

          <!--無需列表標籤--> 

          <ul>

                 <li class=firstBtn>端午節快樂</li>

                 <li></li>

                 <li></li>

          </ul>

          <!--class類命名-->

          <p class=btnLeft>

                            &lt 

          </p>

          <p class=btnRight>

                           &gt

          </p>

</div>

</body>

<!--寫入js-->

 <script>

           //在文檔去獲取多個元素—經過標籤名(」標籤名」)

            var aBtn=document.getElementsByTagName("li");

            var aImg=document.getElementByTagName("img");

            var num=0;

           var oldBtn=aBtn[0];

                  oldBtn.className='firstBtn';

           var oldImg=aImg[0];

                   oldImg.className='firstIng';

           for(i=0;i<6;i++){

 

 

           aBtn[i].index=i;自動屬性(值)

           aBtn[i].onclick=function(){

                 //this指的是誰觸發了次函數,this就指向誰

                 num=this.index;

                  oldBtn.className='';

                  oldBtn=aBtn[num];//更新oldBtn

                  aBtn[num].className='firstBtn';//添加class類名

                   oldImg.className='';

                   oldImg=aImg[this.index];

 

 

                  aImg[num].className='firstImg';/點擊哪一個圖表,顯示哪一個圖片/

 

 

         }

}

var timer

for(i=0;i<6;i++){

 

aBtn[i].index;

aBtn[i].onclick=function(){

clearInterval(timer)//清除計時器

num=this.index;

run();

}

}

//核心

function run(){

   oldBtn.className='';

                  oldBtn=aBtn[num];//更新oldBtn

                  aBtn[num].className='firstBtn';//添加class類名

                   oldImg.className='';

                   oldImg=aImg[num];

 aImg[num].className='firstImg';/點擊哪一個圖表,顯示哪一個圖片/

 

 

}

timer=setInterval(function

{num++;

if(num==6{num=0;}  //==判斷,=賦值

run();

},1000)//每隔1秒執行一次function(){}

 

</script>

</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相關文章
相關標籤/搜索