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

js實(shí)現(xiàn)輪播圖制作方法

 更新時(shí)間:2021年06月25日 13:36:22   作者:一個(gè)愛(ài)前端開(kāi)發(fā)的小朋友  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)輪播圖的制作方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)輪播圖展示的具體代碼,供大家參考,具體內(nèi)容如下

效果如圖所示

代碼如下:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  
  <style type="text/css">
   
   * {
    padding: 0;
    margin: 0;
   }
   .container {
    position: relative;
    width: 600px;
    height: 300px;
    margin:  30px auto;
    overflow: hidden;
   }
       .left {
     display: none;
     position: absolute;
     top: 50%;
     left: -20px;
     transform: translateY(-50%);
     width:50px;
     height: 50px;
     border-top-right-radius: 50%;
     border-bottom-right-radius: 50%;
     background-color: rgba(0,0,0,0.5);
     z-index: 999;
    }
    .left i {
    display: block;
       margin-top: 10px;
    margin-left: 20px;
    width: 30px;
    height: 30px;
    background: url(img/left.png) no-repeat;
    background-size: 30px 30px;
    }
   .right {
    display: none;
    position: absolute;
    top: 50%;
    right: -20px;
    transform: translateY(-50%);
    width:50px;
    height: 50px;
    border-top-left-radius: 50%;
    border-bottom-left-radius: 50%;
    background-color: rgba(0,0,0,0.5);
    z-index: 999;
   }
   .right i {
     display: block;
     margin-top: 10px;
     margin-right: 20px;
     width: 30px;
     height: 30px;
     background: url(img/right.png) no-repeat;
     background-size: 30px 30px;
    }
   
   ul li,ol li {
    list-style: none;
   }
   .picture {
    position: absolute;
   }
   .list {
    position: absolute;
    bottom: 10px;
    left: 10px;
   }
      .list li {
    float: left;
    margin-right: 10px;
    width: 10px;
    height: 10px;
    border-radius: 10px;
    background-color: rgba(0,0,0,0.5);
    cursor: pointer;
   }
   .list .current {
    background-color: #fff;
   }
   .picture li {
    position: absolute;
    width: 600px;
    height: 300px;
   }
   img {
    width: 100%;
    height: 100%;
   }
   
  </style>
 </head>
 <body>
  <div class="container">
   <span class="left"><i></i></span>
   <span class="right"><i></i></span>
   <ul class="picture">
    <li><img src="img/1.jpg" ></li>
    <li><img src="img/2.jpg" ></li>
    <li><img src="img/3.jpg" ></li>
    <li><img src="img/4.jpg" ></li>
    <li><img src="img/5.jpg" ></li>
   </ul>
   <ol class="list">
   </ol>
  </div>
  <script type="text/javascript">
   var picture = document.querySelector('.picture');
   var list = document.querySelector('.list');
   var num=0;
   var circle=0;
   for (i=0;i<picture.children.length;i++)
   {   
    // 設(shè)置圖片的位置
    picture.children[i].style.left = i*600 + 'px';
    // 自動(dòng)生成有序列表
    var  li = document.createElement('li');
    li.setAttribute('index',i);
    
    list.appendChild(li);
    // 給li添加點(diǎn)擊事件
    li.addEventListener('click',function () {
     for (var i=0;i<list.children.length;i++) {
      list.children[i].className = '';
     }
     this.className = 'current';
     var index = this.getAttribute('index');
     num = index;
     circle = index;
     animate(picture,-index*600);
    })
   }
   // 設(shè)置第一個(gè)ol孩子的類(lèi)名
   list.children[0].className = 'current';
   var left = document.querySelector('.left');
   var right = document.querySelector('.right');
   var container = document.querySelector('.container');
   // 設(shè)置鼠標(biāo)經(jīng)過(guò)離開(kāi)事件
   container.addEventListener('mouseover',function () {
    left.style.display = 'block';
    right.style.display = 'block';
    clearInterval(timer)
    timer = null;
   })
   container.addEventListener('mouseleave',function () {
    left.style.display = 'none';
    right.style.display = 'none';
    timer = setInterval(function () {
     right.click();
    },1000);
   })
   
   // js動(dòng)畫(huà)函數(shù)
   function animate (obj,target,callback) {
    clearInterval(obj.timer) 
    obj.timer = setInterval(function () {
     var step = (target - obj.offsetLeft)/10;
     step = step > 0 ? Math.ceil(step) : Math.floor(step);
     if(obj.offsetLeft == target) {
      clearInterval(obj.timer);
      if (callback) {
       callback();
      }
     }
     obj.style.left = obj.offsetLeft + step  + 'px';
    },15)
   }
   
   var first = picture.children[0].cloneNode(true);
   picture.appendChild(first);
   picture.lastChild.style.left = (picture.children.length-1)*600 + 'px';
   //右側(cè)點(diǎn)擊事件
      right.addEventListener('click',function () {
    if (num==picture.children.length-1) {
     picture.style.left = 0;
     num = 0;
    }
    num++;
    animate(picture,-num*600);
    circle ++;
    if (circle == list.children.length) {
     circle = 0;
    }
    
    for (var i = 0;i<list.children.length;i++) {
     list.children[i].className  = '';
    }
    list.children[circle].className  = 'current';
   })
   // 左側(cè)點(diǎn)擊事件
   left.addEventListener('click',function () {
    if (num==0) {
     picture.style.left = -(picture.children.length-1)*600 +'px';
     num = picture.children.length-1;
    }
    num--;
    animate(picture,-num*600);
    circle --;
    if (circle < 0) {
     circle = list.children.length-1;
    }
    
    for (var i = 0;i<list.children.length;i++) {
     list.children[i].className  = '';
    }
    list.children[circle].className  = 'current';
   })
   
   var timer = setInterval(function () {
    // 手動(dòng)調(diào)用
    right.click();
   },1000);
  </script>
 </body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript中交換值的10種方法總結(jié)

    JavaScript中交換值的10種方法總結(jié)

    這篇文章主要給大家總結(jié)介紹了JavaScript中交換值的10種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • js事件觸發(fā)操作實(shí)例分析

    js事件觸發(fā)操作實(shí)例分析

    這篇文章主要介紹了js事件觸發(fā)操作,結(jié)合實(shí)例形式分析了javascript事件觸發(fā)機(jī)制原理、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-06-06
  • JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法詳解

    JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法詳解

    在微信小程序開(kāi)發(fā)時(shí),它的image標(biāo)簽有一個(gè)默認(rèn)高度,這樣你的圖片很可能出現(xiàn)被壓縮變形的情況,所以就需要獲取到圖片的原始尺寸對(duì)image的寬高設(shè)置,本文就來(lái)分享一下JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法吧
    2023-03-03
  • 詳解js的視頻和音頻采集

    詳解js的視頻和音頻采集

    這篇文章給大家講述了關(guān)于js的視頻和音頻采集的相關(guān)知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2018-08-08
  • echarts堆疊柱狀圖柱子之間間隔開(kāi)具體實(shí)現(xiàn)代碼

    echarts堆疊柱狀圖柱子之間間隔開(kāi)具體實(shí)現(xiàn)代碼

    ECharts是一個(gè)強(qiáng)大的數(shù)據(jù)可視化庫(kù),它的堆疊柱狀圖通常用于比較各個(gè)分類(lèi)的數(shù)據(jù)總量,這篇文章主要給大家介紹了echarts堆疊柱狀圖柱子之間間隔開(kāi)具體實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2024-11-11
  • 微信小程序自定義多列選擇器使用詳解

    微信小程序自定義多列選擇器使用詳解

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義多列選擇器使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • js實(shí)現(xiàn)上傳圖片功能

    js實(shí)現(xiàn)上傳圖片功能

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)上傳圖片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • 在VS?Code中使用Snippet?Craft擴(kuò)展提高編碼效率的過(guò)程詳解

    在VS?Code中使用Snippet?Craft擴(kuò)展提高編碼效率的過(guò)程詳解

    這篇文章主要介紹了在VS?Code中使用Snippet?Craft擴(kuò)展提高編碼效率,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-08-08
  • 使用濾鏡設(shè)置透明導(dǎo)致 IE 6/7/8/9 解析異常的解決方法

    使用濾鏡設(shè)置透明導(dǎo)致 IE 6/7/8/9 解析異常的解決方法

    使用濾鏡設(shè)置透明導(dǎo)致 IE 6/7/8/9 解析異常的解決方法,需要的朋友可以參考下。
    2011-04-04
  • JavaScript拖拽、碰撞、重力及彈性運(yùn)動(dòng)實(shí)例分析

    JavaScript拖拽、碰撞、重力及彈性運(yùn)動(dòng)實(shí)例分析

    這篇文章主要介紹了JavaScript拖拽、碰撞、重力及彈性運(yùn)動(dòng)實(shí)現(xiàn)方法,涉及JavaScript數(shù)學(xué)運(yùn)算結(jié)合時(shí)間函數(shù)實(shí)現(xiàn)運(yùn)動(dòng)效果的相關(guān)技巧,需要的朋友可以參考下
    2016-01-01

最新評(píng)論

永新县| 兰州市| 洛川县| 垦利县| 巴东县| 苗栗市| 南城县| 云梦县| 彭阳县| 上饶市| 南阳市| 西和县| 东安县| 公安县| 丹阳市| 顺义区| 法库县| 雷波县| 武川县| 惠来县| 江川县| 易门县| 繁昌县| 昌吉市| 昌图县| 贞丰县| 潜江市| 宜春市| 衡水市| 突泉县| 洪江市| 抚顺市| 涪陵区| 商都县| 万源市| 张家口市| 岚皋县| 峨眉山市| 于田县| 榕江县| 寻甸|