亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

純JS實(shí)現(xiàn)輪播圖

 更新時(shí)間:2017年02月22日 15:14:58   作者:格調(diào)小記  
這幾天一直在看js動(dòng)畫,今天又get到了一個(gè)輪播圖,使用純js實(shí)現(xiàn)的,但是外觀樣式不是很好看,如果大家有需要可以美化下,具體實(shí)現(xiàn)代碼還是很完整的,大家可以參考下

這幾天一直在看js動(dòng)畫,今天又get到了一個(gè)輪播圖,使用純js實(shí)現(xiàn)的,但是沒有美化哈,需要的小伙伴自己美化喔

如下代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>圖片輪播的效果</title>
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
      text-decoration: none;
    }
    body {
      padding: 20px;
    }
    #container {
      position: relative;
      width: 600px;
      height: 400px;
      border: 3px solid #333;
      overflow: hidden;
    }
    #list {
      position: absolute;
      z-index: 1;
      width: 4200px;
      height: 400px;
    }
    #list img {
      float: left;
      width: 600px;
      height: 400px;
    }
    #buttons {
      position: absolute;
      left: 250px;
      bottom: 20px;
      z-index: 2;
      height: 10px;
      width: 100px;
    }
    #buttons span {
      float: left;
      margin-right: 5px;
      width: 10px;
      height: 10px;
      border: 1px solid #fff;
      border-radius: 50%;
      background: #333;
      cursor: pointer;
    }
    #buttons .on {
      background: orangered;
    }
    .arrow {
      position: absolute;
      top: 180px;
      z-index: 2;
      display: none;
      width: 40px;
      height: 40px;
      font-size: 36px;
      font-weight: bold;
      line-height: 39px;
      text-align: center;
      color: #fff;
      background-color: RGBA(0, 0, 0, .3);
      cursor: pointer;
    }
    .arrow:hover {
      background-color: RGBA(0, 0, 0, .7);
    }
    #container:hover .arrow {
      display: block;
    }
    #prev {
      left: 20px;
    }
    #next {
      right: 20px;
    }
  </style>
</head>
<body>
<div id="container">
  <div id="list" style="left: -600px;">
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="無縫滾動(dòng)" />
    <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="無縫滾動(dòng)" />
  </div>
  <div id="buttons">
    <span index="1" class="on"></span>
    <span index="2"></span>
    <span index="3"></span>
    <span index="4"></span>
    <span index="5"></span>
  </div>
  <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="prev" class="arrow">&lt;</a>
  <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="next" class="arrow">&gt;</a>
</div>
<script type="text/javascript">
  window.onload=function(){
    var container = document.getElementById("container");
    var list = document.getElementById("list");
    var buttons = document.getElementById("buttons").getElementsByTagName('span');
    var prev = document.getElementById("prev");
    var next = document.getElementById("next");
    var index = 1;
   function animate(offset){
     var newLeft = parseInt(list.style.left) + offset;
     list.style.left = newLeft + 'px';
     if(newLeft<-3000){
       list.style.left= -600 +'px';
     }
     if(newLeft>-600){
       list.style.left = -3000 + 'px';
     }
   }
   function buttonsshow(){
     for(var i =0; i<buttons.length;i++){
       if(buttons[i].className == 'on'){
         buttons[i].className='';
       }
     }
     buttons[index-1].className='on';
   }
   prev.onclick = function(){
     index-=1;
     if(index<1)
     {
       index=5;
     }
     buttonsshow();
     animate(600);
   };
   next.onclick = function(){
     index+=1;
     if(index>5){
       index=1;
     }
     buttonsshow();
     animate(-600);
   };
   //自動(dòng)播放
   var timer;
    function play(){
      timer= setInterval(function(){
        next.onclick();
      },1000)
    }
    play();
    function stop(){
      clearInterval(timer);
    }
    container.onmouseover=stop;
    container.onmouseout=play;
for(var i=0; i<buttons.length; i++){
  ( function(i){
      buttons[i].onclick=function(){
        var clickindex= parseInt(this.getAttribute('index'));
        var offset = 600*(index-clickindex);
        animate(offset);
        index = clickindex;
        buttonsshow();
      }
  })(i);
}
  }
</script>
</body>
</html>

以上所述是小編給大家介紹的純JS實(shí)現(xiàn)輪播圖,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • JavaScript中document.forms[0]與getElementByName區(qū)別

    JavaScript中document.forms[0]與getElementByName區(qū)別

    在很多情況下JavaScript中document.forms[0]與getElementByName這兩種用法沒有區(qū)別,這片文章詳細(xì)的解釋了兩者的區(qū)別和用法,有興趣的朋友可以參考一下。
    2015-01-01
  • TypeScript實(shí)現(xiàn)數(shù)組和樹的相互轉(zhuǎn)換

    TypeScript實(shí)現(xiàn)數(shù)組和樹的相互轉(zhuǎn)換

    樹或者圖是個(gè)比較抽象的概念,并不存在這樣的數(shù)據(jù)類型。數(shù)組就比較簡(jiǎn)單了,因此數(shù)組和樹的轉(zhuǎn)換可以理解為數(shù)組和對(duì)象之間的轉(zhuǎn)換。本文將用TypeScript實(shí)現(xiàn)數(shù)組和樹的相互轉(zhuǎn)換,感興趣的可以了解一下
    2022-06-06
  • JavaScript promise的使用和原理分析

    JavaScript promise的使用和原理分析

    Promise 是一個(gè) ECMAScript 6 提供的類,目的是更加優(yōu)雅地書寫復(fù)雜的異步任務(wù)。由于 Promise 是 ES6 新增加的,所以一些舊的瀏覽器并不支持,蘋果的 Safari 10 和 Windows 的 Edge 14 版本以上瀏覽器才開始支持 ES6 特性
    2023-04-04
  • JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲

    JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)前端飛機(jī)大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Javascript實(shí)現(xiàn)hashcode函數(shù)實(shí)現(xiàn)對(duì)象比較與原理說明

    Javascript實(shí)現(xiàn)hashcode函數(shù)實(shí)現(xiàn)對(duì)象比較與原理說明

    在JavaScript中,數(shù)值的比較是比較簡(jiǎn)單的,使用相等(==)和全等(===)符號(hào)基本上可以解決大多數(shù)非對(duì)象的比較。但是相等(==)和全等(===)符號(hào)在對(duì)象 object 的比較上,就不能滿足所有的要求了
    2023-06-06
  • 基于JavaScript實(shí)現(xiàn)雪花許愿墻特效

    基于JavaScript實(shí)現(xiàn)雪花許愿墻特效

    新的一年就要到了,你一定有很多想許下的愿望吧!今天小編就為大家?guī)砹艘粋€(gè)基于Html+CSS+JavaScript實(shí)現(xiàn)的帶雪花的許愿墻特效,需要的可以了解一下
    2022-01-01
  • js轉(zhuǎn)換對(duì)象為xml

    js轉(zhuǎn)換對(duì)象為xml

    本文主要介紹了js轉(zhuǎn)換對(duì)象為xml的方法。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • axios處理重復(fù)請(qǐng)求的方法小結(jié)

    axios處理重復(fù)請(qǐng)求的方法小結(jié)

    這篇文章主要為大家詳細(xì)介紹了如何使用發(fā)布訂閱者模式來處理重復(fù)的axios請(qǐng)求,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • javascript css紅色經(jīng)典選項(xiàng)卡效果實(shí)現(xiàn)代碼

    javascript css紅色經(jīng)典選項(xiàng)卡效果實(shí)現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了javascript css紅色經(jīng)典選項(xiàng)卡效果的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2016-05-05
  • 詳解微信小程序工程化探索之webpack實(shí)戰(zhàn)

    詳解微信小程序工程化探索之webpack實(shí)戰(zhàn)

    這篇文章主要介紹了詳解微信小程序工程化探索之webpack實(shí)戰(zhàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04

最新評(píng)論