欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實(shí)現(xiàn)垂直無(wú)限輪播的方法分析

 更新時(shí)間:2019年07月16日 11:20:40   作者:愛(ài)在彩虹  
這篇文章主要介紹了jquery實(shí)現(xiàn)垂直無(wú)限輪播的方法,結(jié)合實(shí)例形式分析了jQuery無(wú)限輪播相關(guān)界面布局、樣式與頁(yè)面元素動(dòng)態(tài)操作實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了jquery實(shí)現(xiàn)垂直無(wú)限輪播的方法。分享給大家供大家參考,具體如下:

javascript垂直輪播,依賴(lài)于jquery實(shí)現(xiàn)的,并且首尾無(wú)縫銜接。原理很簡(jiǎn)單,就不講述了,直接貼源碼。

1.HTML節(jié)點(diǎn)

<div class="banner_group">
    <ul id="banner">
      <!-- 緩存末項(xiàng),實(shí)現(xiàn)滑動(dòng)到最開(kāi)始后,無(wú)限輪播 -->
      <li style="background-color: chartreuse">第四頁(yè)</li>
      <li style="background-color: #f6894d">第一頁(yè)</li>
      <li style="background-color: royalblue">第二頁(yè)</li>
      <li style="background-color: red">第三頁(yè)</li>
      <li style="background-color: chartreuse">第四頁(yè)</li>
      <!-- 緩存首項(xiàng),實(shí)現(xiàn)滑動(dòng)到最后過(guò)后,無(wú)限輪播 -->
      <li style="background-color: #f6894d">第一頁(yè)</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準(zhǔn)備

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

4.JavaScript代碼

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

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

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論