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

原生js滑動(dòng)輪播封裝

 更新時(shí)間:2020年07月31日 11:12:25   作者:Seeyoucm  
這篇文章主要為大家詳細(xì)介紹了原生js滑動(dòng)輪播封裝,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了原生js滑動(dòng)輪播的具體代碼,供大家參考,具體內(nèi)容如下

封裝滑動(dòng)輪播

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>cmm無(wú)縫輪播</title>
 <style type="text/css">
 *{margin: 0 ;padding : 0}
  #container{
   height: 470px;
   width: 590px;
   border: 1px solid red;
   position: relative;
   margin: 50px auto;
  }
  #box{
   position: absolute;
   list-style: none;
   
  }
  #box li{
   float: left;
  }
  #pages {
 width: 100%;
 height: 30px;
 background: #ccc;
 position: absolute;
 bottom: 0;
 }

 #pages i {
 width: 20px;
 height: 20px;
 display: inline-block;
 border-radius: 10px;
 background: #fff;
 margin: 5px;
 }

 #pages i.current {
 background: #f00;
 }

 #prev, #next {
 width: 45px;
 height: 100px;
 position: absolute;
 top: 0;
 bottom: 0;
 margin: auto;
 background: #ccc;
 line-height: 100px;
 text-align: center;
 font-size: 40px;
 color: #fff;
 }
 #next {
 right: 0;
 }
 </style>
</head>
<body>
 <div id="container">
 <ul id="box">
 <li><img src="images/1.jpg"></li>
 <li><img src="images/2.jpg"></li>
 <li><img src="images/3.jpg"></li>
 <li><img src="images/4.jpg"></li>
 </ul>
 <div id="pages"></div>
 <div id="prev"><</div>
 <div id="next">></div>
 </div>

 <script src="js/tools.js"></script>
 <script>
  var lis = $("li"),
   length = lis.length,
   liWidth = lis[0].clientWidth,
   currentIndex = 0,
   nextIndex = 1,
   timer = null,
   move = null,
   circls = null,
   durations = 2000;

 // 動(dòng)態(tài)設(shè)置ul寬度
 $("#box").style.width = length * liWidth + "px";

 // 動(dòng)態(tài)設(shè)置小圓點(diǎn)
 var html = "";
 for(var i = 0 ;i <length ;i++){
  html += "<i></i>"
 }
 $("#pages").innerHTML= html;
 circls = $("i");
 circls[0].className = "current";

 // 切換動(dòng)畫(huà)
 move = function(){
  // 設(shè)置box運(yùn)動(dòng)終點(diǎn)值
  var _left = -1 * nextIndex * liWidth;

  // 開(kāi)始動(dòng)畫(huà)
  animate($("#box"),{left:_left},200)

  // 修改小圓點(diǎn)樣式
  circls[currentIndex].className = "";
  circls[nextIndex].className = "current";

  // 修改索引
  currentIndex = nextIndex;
  nextIndex++;
  if(nextIndex >= length){
   nextIndex = 0;
  }
 }


 // 自動(dòng)動(dòng)畫(huà)
 timer = setInterval(move, durations)

 // container中鼠標(biāo)移入,移出事件
 on($("#container"),"mouseenter",function(){
  clearInterval(timer);
 })
 on($("#container"),"mouseleaver",function(){
  timer = setInterval(move, durations);
 })

 // 點(diǎn)擊小圓點(diǎn),切換至對(duì)應(yīng)的圖片
 on($("#pages"),"click",function(e){
  e = e || event;
  var src = e.target || src.Element;
  if(src.nodeName === "I"){
   var _index = Array.from(circls).indexOf(src);
   if(_index === currentIndex){
    return
   }
   nextIndex = _index;
   move();
  }
 })

 // 點(diǎn)擊翻頁(yè)進(jìn)行切換
 on($("#prev"),"click",function(){
  nextIndex = currentIndex - 1;
  if(nextIndex < 0){
   nextIndex = length;
  }
  move();
 })
 on($("#next"),"click",function(){
  move();
 })
 </script>
</body>
</html>

更多關(guān)于輪播圖效果的專題,請(qǐng)點(diǎn)擊下方鏈接查看學(xué)習(xí)

javascript圖片輪播效果匯總

jquery圖片輪播效果匯總

Bootstrap輪播特效匯總

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

相關(guān)文章

  • JS 獲取滾動(dòng)條高度示例代碼

    JS 獲取滾動(dòng)條高度示例代碼

    滾動(dòng)條高度如何獲取,方法有很多,在本文將為大家詳細(xì)介紹下如何使用js做到,下面有個(gè)不錯(cuò)的示例,感興趣的朋友不要錯(cuò)過(guò)
    2013-10-10
  • Javascript面象對(duì)象成員、共享成員變量實(shí)驗(yàn)

    Javascript面象對(duì)象成員、共享成員變量實(shí)驗(yàn)

    Javascript 面象對(duì)象成員、共享成員變量實(shí)驗(yàn),需要的朋友可以參考下。
    2010-11-11
  • 詳解JavaScript的Date對(duì)象(制作簡(jiǎn)易鐘表)

    詳解JavaScript的Date對(duì)象(制作簡(jiǎn)易鐘表)

    這篇文章主要為大家詳細(xì)介紹了JavaScript的Date對(duì)象,和大家分享如何制作簡(jiǎn)易鐘表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • 怎樣用Javascript實(shí)現(xiàn)建造者模式

    怎樣用Javascript實(shí)現(xiàn)建造者模式

    這篇文章主要介紹了怎樣用Javascript實(shí)現(xiàn)建造者模式,想學(xué)習(xí)設(shè)計(jì)模式的同學(xué),可以參考下
    2021-04-04
  • 最新評(píng)論

    沙湾县| 贺兰县| 绵阳市| 壶关县| 鹤峰县| 水城县| 舒兰市| 九江市| 洪江市| 民权县| 三门县| 浏阳市| 湖口县| 公主岭市| 潮州市| 越西县| 米脂县| 辽源市| 扎鲁特旗| 澄江县| 苍梧县| 沂源县| 江永县| 本溪市| 沾益县| 合江县| 平舆县| 南和县| 遂平县| 历史| 广安市| 利川市| 环江| 洛扎县| 东平县| 巴马| 桐庐县| 彩票| 乐平市| 灵武市| 手游|