javascript-- 基於jQuery的模仿移動端上拉載入更多控制項

來源:互聯網
上載者:User

標籤:font   doc   timer   color   back   asc   動效   name   控制項   

簡單實現手機端上拉載入更多,通過觸發trigger()事件,觸發原先已經寫好的請求

css樣式

.more{                padding: 10px 10px;                height:50px;                background:#fff;                background-clip:content-box;                text-align: center;                line-height:50px;                font-family:"Microsoft Yahei";                display: none;                }

 

html代碼

        <div class="more" data-page="1" data-rname="">            載入更多        </div>        

js代碼

 1 /** 2  *實現滾動效果  3  */ 4 $(function(){ 5     var clientH = $(window).height();//螢幕高度 6     var h =$(document).height()- $(window).scrollTop(); 7     var timer = null; 8     $(window).on("touchmove",function(){ 9         var scrollH = $(document).height();10         h = scrollH-$(this).scrollTop();11         if(clientH >= h){12             $(".more").show();13             timer = setTimeout(function(){14                 $(".more").html("鬆開載入");15             }, 1000);16         }else if(clientH >= h-$(".more").height()){17             18             $(".more").html("載入更多");19             $(".more").hide();20         }21     });22     //記錄開始按下到鬆開的時間23 24     var startTime, endTime;25     $(window).on("touchstart",function(event){26         startTime = new Date().getTime();27         $(".more").html("載入更多");28     });29     $(window).on("touchend",function(event){30         h =$(document).height()- $(window).scrollTop();31         if(clientH >= h){32             endTime = new Date().getTime();33             if(endTime - startTime > 900){34                 $(".more").trigger("click");35                 $(".more").show();36                 $(".more").html("載入中...");37             }else{38                 clearTimeout(timer);39                 $(".more").html("載入更多");40                 $(".more").hide();41                 42             }43         }else{44             clearTimeout(timer);45             $(".more").html("載入更多");46             $(".more").hide();47             48         }49         50     });51 });

 

javascript-- 基於jQuery的模仿移動端上拉載入更多控制項

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.