国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jquery實現垂直無限輪播的方法分析

2019-11-19 11:10:42
字體:
來源:轉載
供稿:網友

本文實例講述了jquery實現垂直無限輪播的方法。分享給大家供大家參考,具體如下:

javascript垂直輪播,依賴于jquery實現的,并且首尾無縫銜接。原理很簡單,就不講述了,直接貼源碼。

1.HTML節點

<div class="banner_group">    <ul id="banner">      <!-- 緩存末項,實現滑動到最開始后,無限輪播 -->      <li style="background-color: chartreuse">第四頁</li>      <li style="background-color: #f6894d">第一頁</li>      <li style="background-color: royalblue">第二頁</li>      <li style="background-color: red">第三頁</li>      <li style="background-color: chartreuse">第四頁</li>      <!-- 緩存首項,實現滑動到最后過后,無限輪播 -->      <li style="background-color: #f6894d">第一頁</li>    </ul>    <div class="scrollPageBtn">      <div style="width: 100%;height: 100%;position: relative;">        <label id="last" style="width:100%;position: absolute;top: 0;text-align: center">↑</label>        <label id="next" style="width:100%;position: absolute;bottom: 0;text-align: center">↓</label>      </div>    </div></div>

2.CSS樣式

<style>    body{      margin:0;      padding: 0;    }    .banner_group{      width: 300px;      height: 500px;      overflow: hidden;      position: relative;    }    .scrollPageBtn{      width: 30px;      height: 100%;      position: absolute;      top: 0;      left: 40%;      background-color: #b2b2b2;      opacity: 0.2;    }    ul{      list-style: none;      width: 100%;      height: 100%;      margin: 0;      padding: 0;      position: relative;    }    ul li{      width: 100%;      height: 100%;      color: white;      font-size: 25px;    }</style>

3.JQuery準備

<!-- 引入jquery --><script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

4.JavaScript代碼

<script>    var index = 0; // 保存當前所在項    /* 是否允許點擊滑動動畫,如果正在執行動畫的過程中,    則禁止點擊,如果動畫完成后,則允許點擊,    避免由于連點,出現畫面不正常問題. */    var allowClick = true; //    // 頁面加載完成后調用    $(function(){      index = 1; // 初始顯示第2項  /* 注意:第一項是用來緩存末項的,實現無縫連接準備的,所以最開始顯示的應該是第2項 */      $("#banner").css("bottom", "500px"); // 準備初始顯示項  // 上一頁      $("#last").on("click", function(){        if(allowClick){          allowClick = false;          index--; // 上一頁,--   // 如果已經到了最開始過后,動畫完成后,定位到末項          if(index == 0){            $("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {              index = 4;              $("#banner").css("bottom", "2000px"); // 定位到末項              allowClick = true;            });          }else{            $("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {              allowClick = true;            });          }        }      });  // 下一頁      $("#next").on("click", function(){        if(allowClick){          allowClick = false;          if(index <= 5){            index ++; // 下一頁++            if(index == 5){              $("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {                index = 1;                $("#banner").css("bottom", "500px");                allowClick = true;              });            }else{              $("#banner").animate({bottom: (index * 500) + 'px'}, "fast", "swing", function () {                allowClick = true;              });            }          }        }      });    });</script>

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 施秉县| 宿州市| 康平县| 菏泽市| 都江堰市| 高雄市| 敖汉旗| 迁安市| 龙井市| 梁河县| 南投市| 新邵县| 青海省| 阜南县| 贵溪市| 阜城县| 阿坝| 辰溪县| 珠海市| 乌兰浩特市| 宜黄县| 托克逊县| 依兰县| 富顺县| 迁西县| 大庆市| 吉水县| 新田县| 正安县| 霍城县| 宁安市| 勃利县| 霍林郭勒市| 钟山县| 石狮市| 元氏县| 明溪县| 天柱县| 古交市| 五台县| 铜山县|