成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

原生js和css實(shí)現(xiàn)圖片輪播效果

本文實(shí)例為大家分享了javascript圖片輪播效果的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)專(zhuān)業(yè)提供雅安機(jī)房托管服務(wù),為用戶提供五星數(shù)據(jù)中心、電信、雙線接入解決方案,用戶可自行在線購(gòu)買(mǎi)雅安機(jī)房托管服務(wù),并享受7*24小時(shí)金牌售后服務(wù)。

<!DOCTYPE HTML> 
<html lang="zh-CN"> 
 
<head> 
  <meta charset="utf-8"> 
  <title>圖片輪播</title> 
   
  <style> 
    #box { 
      width:506px; 
      height:306px; 
      margin: 20px auto; 
      border:3px solid black; 
      position:relative; 
      background-color:orange; 
      overflow: hidden; 
      /*overflow: hidden;*/ 
    } 
    .pic { 
      position: absolute; 
      width:500px; 
      height:300px; 
      line-height: 300px; 
      text-align: center; 
      font-size: 100px; 
      color:white; 
      bottom:0; 
    } 
    .red { 
      background-color:red; 
    } 
    .green { 
      background-color:green; 
    } 
    .blue { 
      background-color:blue; 
    } 
    .orange{ 
      background-color: orange; 
    } 
    .move { 
      bottom:300px; 
      transition:bottom 3s; /* 設(shè)置圖片移動(dòng)消耗的時(shí)間*/ 
    } 
  </style> 
</head> 
 
<body> 
  <div id="box"> 
    <div id="pic1" class="pic red">1</div> 
    <div id="pic2" class="pic green">2</div> 
    <div id="pic3" class="pic blue">3</div> 
    <div id="pic3" class="pic orange">4</div> 
  </div> 
   
   
  <script> 
    window.addEventListener('load',function(){ 
      var pics = document.getElementsByClassName('pic'); 
       
      //為每個(gè)pic元素設(shè)置z-index的值 
      for(let i=0;i<pics.length;i++){ 
        pics[i].style.zIndex = pics.length-i; 
      } 
       
      //循環(huán)播放圖片的函數(shù) 
      var loopPics = (function(){ 
        var index=0; 
        return function(pics,delay){ 
          var recall = function(pic){ 
            //給圖片增加move類(lèi),調(diào)用css的transition屬性播放移動(dòng)動(dòng)畫(huà) 
            pic.className += ' move'; 
            setTimeout(function(){ 
              //取消圖片的move類(lèi),圖片返回原位 
              pic.className=pic.className.replace(' move',''); 
              //改變圖片組的堆疊順序。最外的圖片放到最下面,其他圖片依次向外移動(dòng) 
              for(let i=0;i<pics.length;i++){ 
                if(pics[i].style.zIndex==pics.length){ 
                  pics[i].style.zIndex=1; 
                } else { 
                  pics[i].style.zIndex=pics[i].style.zIndex*1+1; 
                } 
              } 
              index++; 
              if(index==pics.length) index=0; 
              recall(pics[index]); 
            },delay); 
          }; 
          recall(pics[index]); 
        }; 
      })(); 
      //調(diào)用函數(shù),循環(huán)播放。delay的時(shí)間需要大于等于css動(dòng)畫(huà)里設(shè)置的圖片移動(dòng)時(shí)間 
      loopPics(pics,4000); 
    }); 
 
  </script> 
</body> 
 
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當(dāng)前文章:原生js和css實(shí)現(xiàn)圖片輪播效果
當(dāng)前鏈接:http://jinyejixie.com/article26/psppcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、標(biāo)簽優(yōu)化、品牌網(wǎng)站建設(shè)搜索引擎優(yōu)化、網(wǎng)站排名、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
高要市| 青浦区| 根河市| 富锦市| 丰顺县| 赤壁市| 高阳县| 息烽县| 黄平县| 亚东县| 巨野县| 手游| 文山县| 博爱县| 彝良县| 乌拉特前旗| 开远市| 吉安县| 绥德县| 巴里| 蓬安县| 呼图壁县| 汶上县| 郓城县| 屯昌县| 九龙县| 晋城| 牙克石市| 台前县| 含山县| 凤阳县| 东台市| 同江市| 游戏| 夹江县| 阳江市| 安阳县| 本溪市| 苗栗县| 阿坝县| 房山区|