• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    使用JS實現(xiàn)圖片輪播的實例(前后首尾相接)

    來源:懂視網 責編:小采 時間:2020-11-27 22:29:12
    文檔

    使用JS實現(xiàn)圖片輪播的實例(前后首尾相接)

    使用JS實現(xiàn)圖片輪播的實例(前后首尾相接):最近各種跑面試,終于還是被問到這個,一腦子漿糊,當時沒想出來首尾相接怎么搞,回來之后研究了一波,終于搞出來了,不多說,直接看代碼 代碼參考了一位已經寫好了圖片輪播功能的(再次表示感謝),但是沒有首尾相接的功能,本人在此基礎上增加了首尾相接功
    推薦度:
    導讀使用JS實現(xiàn)圖片輪播的實例(前后首尾相接):最近各種跑面試,終于還是被問到這個,一腦子漿糊,當時沒想出來首尾相接怎么搞,回來之后研究了一波,終于搞出來了,不多說,直接看代碼 代碼參考了一位已經寫好了圖片輪播功能的(再次表示感謝),但是沒有首尾相接的功能,本人在此基礎上增加了首尾相接功

    最近各種跑面試,終于還是被問到這個,一腦子漿糊,當時沒想出來首尾相接怎么搞,回來之后研究了一波,終于搞出來了,不多說,直接看代碼

    代碼參考了一位已經寫好了圖片輪播功能的(再次表示感謝),但是沒有首尾相接的功能,本人在此基礎上增加了首尾相接功能。

    效果如下:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>圖片輪播</title>
     <style type="text/css">
     body,div,ul,li,a,img{margin: 0;padding: 0;}
     ul,li{list-style: none;}
     a{text-decoration: none;}
     #wrapper{
     position: relative;
     margin: 30px auto; /* 上下邊距30px,水平居中 */
     width: 400px;
     height: 200px;
     }
     #banner{
     position:relative;
     width: 400px;
     height: 200px;
     overflow: hidden;
     }
     .imgList{
     position:relative;
     width:2000px;
     height:200px;
     z-index: 10;
     overflow: hidden;
     }
     .imgList li{float:left;display: inline;}
     #prev,
     #next{
     position: absolute;
     top:80px;
     z-index: 20;
     cursor: pointer;
     opacity: 0.2;
     filter:alpha(opacity=20);
     }
     #prev{left: 10px;}
     #next{right: 10px;}
     #prev:hover,
     #next:hover{opacity: 0.5;filter:alpha(opacity=50);}
    
    </style>
    </head>
    <body>
     <div id="wrapper"><!-- 最外層部分 -->
     <div id="banner"><!-- 輪播部分 -->
     <ul class="imgList"><!-- 圖片部分 -->
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="./img/1.jpg" width="400px" height="200px" alt="1"></a></li>
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="./img/2.jpg" width="400px" height="200px" alt="2"></a></li>
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="./img/3.jpg" width="400px" height="200px" alt="3"></a></li>
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="./img/4.jpg" width="400px" height="200px" alt="4"></a></li>
     <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="./img/5.jpg" width="400px" height="200px" alt="5"></a></li>
     </ul>
     <img src="./img/prev.png" width="40px" height="40px" id="prev">
     <img src="./img/next.png" width="40px" height="40px" id="next">
    </div>
    </div>
    <script type="text/javascript" src="./js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
    var curIndex = 0, //當前index
     imgLen = $(".imgList li").length; //圖片總數(shù)
    $(".imgList").css("width", (imgLen+1)*400+"px");
    // 定時器自動變換3秒每次
    var autoChange = setInterval(function(){
     if(curIndex < imgLen-1){
     curIndex ++;
     }else{
     curIndex = 0;
     }
     //調用變換處理函數(shù)
     changeTo(curIndex);
    },3000);
    
    //左箭頭滑入滑出事件處理
    $("#prev").hover(function(){
     //滑入清除定時器
     clearInterval(autoChange);
    }, function(){
     //滑出則重置定時器
     autoChangeAgain();
    });
    
    //左箭頭點擊處理
    $("#prev").click(function(){
     //根據curIndex進行上一個圖片處理
     // curIndex = (curIndex > 0) ? (--curIndex) : (imgLen - 1);
     if (curIndex == 0) {
     var element = document.createElement("li");
     element.innerHTML = $(".imgList li")[imgLen - 1].innerHTML;
     // $(".imgList li")[imgLen - 1].remove();
     $(".imgList").prepend(element);
     $(".imgList").css("left", -1*400+"px");
     changeTo(curIndex);
     curIndex = -1;
     } else if (curIndex == -1) {
     $(".imgList").css("left", -(imgLen-1)*400+"px");
     curIndex = imgLen-2;
     $(".imgList li")[0].remove();
     changeTo(curIndex);
     } else {
     --curIndex;
     changeTo(curIndex);
     }
    
    });
    
    //右箭頭滑入滑出事件處理
    $("#next").hover(function(){
     //滑入清除定時器
     clearInterval(autoChange);
    }, function(){
     //滑出則重置定時器
     autoChangeAgain();
    });
    //右箭頭點擊處理
    $("#next").click(function(){
     // curIndex = (curIndex < imgLen - 1) ? (++curIndex) : 0;
     console.log(imgLen);
     if (curIndex == imgLen-1) {
     var element = document.createElement("li");
     element.innerHTML = $(".imgList li")[0].innerHTML;
     // $(".imgList li")[0].remove();
     $(".imgList").append(element);
     ++curIndex;
     } else if (curIndex == imgLen) {
     curIndex = 0;
     $(".imgList").css("left", "0px");
     $(".imgList li")[imgLen].remove();
     curIndex++;
     } else {
     ++curIndex;
     }
     changeTo(curIndex);
    });
    
    //清除定時器時候的重置定時器--封裝
    function autoChangeAgain(){
     autoChange = setInterval(function(){
     if(curIndex < imgLen-1){
     curIndex ++;
     }else{
     curIndex = 0;
     }
     //調用變換處理函數(shù)
     changeTo(curIndex);
     },3000);
    }
    
    
    function changeTo(num){
     var goLeft = num * 400;
     $(".imgList").animate({left: "-" + goLeft + "px"},500);
    }
    </script>
    </body>
    </html>

    以上這篇使用JS實現(xiàn)圖片輪播的實例(前后首尾相接)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    使用JS實現(xiàn)圖片輪播的實例(前后首尾相接)

    使用JS實現(xiàn)圖片輪播的實例(前后首尾相接):最近各種跑面試,終于還是被問到這個,一腦子漿糊,當時沒想出來首尾相接怎么搞,回來之后研究了一波,終于搞出來了,不多說,直接看代碼 代碼參考了一位已經寫好了圖片輪播功能的(再次表示感謝),但是沒有首尾相接的功能,本人在此基礎上增加了首尾相接功
    推薦度:
    標簽: 圖片 輪播 輪播圖
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 久久久一本精品99久久精品88| 999国内精品永久免费观看| 无码人妻精品一区二区三区66| 国产高清在线精品一区| 呦交小u女国产精品视频| 国产精品美女久久久久AV福利| 国产精品天天看天天狠| 一本色道久久88精品综合| 国产精品永久免费视频| 久久91精品国产91久久麻豆| 国产午夜福利精品一区二区三区| 亚洲国产精品成人AV无码久久综合影院| 9久热这里只有精品| 精品精品国产自在久久高清| 国产精品人成在线播放新网站| 亚洲国产精品VA在线看黑人 | 精品一区二区三区在线成人| 伊人精品视频在线| 日韩精品亚洲专区在线观看 | 一区二区日韩国产精品| 欧美精品亚洲人成在线观看| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 欧美精品人人做人人爱视频| 国产午夜精品久久久久九九电影 | 99国产精品一区二区| 国产精品一久久香蕉国产线看观看| 日韩精品无码一区二区三区不卡| 中文字幕精品一区| 亚洲午夜精品一级在线播放放| 亚洲国模精品一区| 亚洲AV无码成人精品区在线观看 | www.亚洲精品| 久久国产精品久久精品国产| 久久99国产精品久久久 | 久久99久久99小草精品免视看| 91精品啪在线观看国产| 国产午夜精品理论片久久影视| 精品国产日产一区二区三区| 91精品国产麻豆国产自产在线| 国产高清精品一区| 久久国产成人亚洲精品影院|