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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:36:56
字體:
來源:轉載
供稿:網友

本文實例講述了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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 游戏| 鸡泽县| 百色市| 泾川县| 麻城市| 申扎县| 沙田区| 丹棱县| 乌拉特后旗| 绥化市| 建平县| 平利县| 潢川县| 城步| 和田市| 阜宁县| 观塘区| 文安县| 高台县| 曲靖市| 宁夏| 乌什县| 荃湾区| 郓城县| 图木舒克市| 昌黎县| 鲁甸县| 大荔县| 九龙坡区| 阳山县| 廊坊市| 东阿县| 密山市| 临澧县| 武山县| 四会市| 荣昌县| 磴口县| 昌宁县| 香港 | 海阳市|