最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解微信小程序開發(fā)之下拉刷新 上拉加載

 更新時間:2016年11月24日 15:54:59   作者:dzp_coder  
本篇文章主要介紹了微信小程序開發(fā)之下拉刷新 上拉加載,具有一定的參考價值,有興趣的可以了解一下。

微信小程序中的下拉刷新,上拉加載的功能很常見,目前我知道的有兩種可行的方法,一是scroll-view,二是整個頁面刷新.今天說說第一種,自己造輪子,難免有些瑕疵,日后慢慢完善.

上gif:
原理: scroll-view中有監(jiān)聽滑動的方法,這個跟Android類似.其中用到了滑動到頂部,滑動到底部的方法.

1.下拉刷新,在滑動到頂部時,bindscrolltoupper被調(diào)用,根據(jù)自己的業(yè)務(wù)邏輯請求即可.我的demo只是隨機換了個關(guān)鍵字.

2.上拉加載,在滑動到底部時,bindscrolltolower被調(diào)用,我這里是頁數(shù)加一,根據(jù)自己的業(yè)務(wù)邏輯修改,然后將獲取到的集合添加到scroll-view的數(shù)據(jù)集合里即可.

上代碼:

1.index.js

//index.js 
//獲取應(yīng)用實例 
var app = getApp() 
Page({ 
 data: { 
 words: [], 
 windowHeight: 0,//獲取屏幕高度 
 refreshHeight: 0,//獲取高度 
 refreshing: false,//是否在刷新中 
 refreshAnimation: {}, //加載更多旋轉(zhuǎn)動畫數(shù)據(jù) 
 clientY: 0,//觸摸時Y軸坐標 
 }, 
 onLoad: function () { 
 var _this = this; 
 //獲取屏幕高度 
 wxgetSystemInfo({ 
  success: function (res) { 
  _thissetData({ 
   windowHeight: reswindowHeight 
  }) 
  consolelog("屏幕高度: " + reswindowHeight) 
  } 
 }) 
 //獲取words 
 wxrequest({ 
  url: 'http://apiavatardatacn/ChengYu/Search?key=77f072d28eb141c8b6dda145ca364b92&keyWord=好', 
  complete: function (res) { 
  if (resdatareason == 'Succes') { 
   _thissetData({ 
   words: resdataresult 
   }) 
  } 
  } 
 }) 
 }, 
 scroll: function () { 
 consolelog("滑動了") 
 }, 
 lower: function () { 
 var start = 0; 
 start += 1; 
 consolelog("加載了") 
 var _this = this; 
 wxrequest({ 
  url: 'http://apiavatardatacn/ChengYu/Search', 
  data: { 
  key: '77f072d28eb141c8b6dda145ca364b92', keyWord: '好', page: start 
  }, 
  complete: function (res) { 
  if (resdatareason == 'Succes') { 
   var words = _thisdatawordsconcat(resdataresult); 
   _thissetData({ 
   words: words 
   }) 
  } 
  } 
 }) 
 }, 
 upper: function () { 
 consolelog("下拉了") 
 //獲取用戶Y軸下拉的位移 
 
 if (thisdatarefreshing) return; 
 thissetData({ refreshing: true }); 
 updateRefreshIconcall(this); 
 var _this = this; 
 var i = Mathrandom() //獲得0-1的隨機數(shù) 
 i = Mathceil(i * 10) //乘以10并向上去整 
 var words = ['龍', '一', '萬', '千', '浩', '金', '得', '而', '可', '人']; 
 var word = words[i]; 
 wxrequest({ 
  url: 'http://apiavatardatacn/ChengYu/Search?key=77f072d28eb141c8b6dda145ca364b92&keyWord=' + word, 
 
  complete: function (res) { 
  if (resdatareason == 'Succes') { 
   setTimeout(function () { 
   _thissetData({ 
    words: resdataresult 
   }) 
   }, 2000) 
  } 
  setTimeout(function () { 
   _thissetData({ 
   refreshing: false 
   }) 
  }, 2500) 
  } 
 }) 
 }, 
 start: function (e) { 
 var startPoint = etouches[0] 
 var clientY = startPointclientY; 
 thissetData({ 
  clientY: clientY, 
  refreshHeight: 0 
 }) 
 }, 
 end: function (e) { 
 var endPoint = echangedTouches[0] 
 var y = (endPointclientY - thisdataclientY) * 6; 
 if (y > 50) { 
  y = 50; 
 } 
 thissetData({ 
  refreshHeight: y 
 }) 
 }, 
 move: function (e) { 
 consolelog("下拉滑動了") 
 } 
}) 
 
/** 
 * 旋轉(zhuǎn)上拉加載圖標 
 */ 
function updateRefreshIcon() { 
 var deg = 0; 
 var _this = this; 
 consolelog('旋轉(zhuǎn)開始了') 
 var animation = wxcreateAnimation({ 
 duration: 1000 
 }); 
 
 var timer = setInterval(function () { 
 if (!_thisdatarefreshing) 
  clearInterval(timer); 
 animationrotateZ(deg)step();//在Z軸旋轉(zhuǎn)一個deg角度 
 deg += 360; 
 _thissetData({ 
  refreshAnimation: animationexport() 
 }) 
 }, 1000); 
} 

2.index.wxml

<!--indexwxml--> 
 <view class="refresh-block" style="height: {{refreshHeight}}px;" wx:if="{{refreshing}}"> 
 <image animation="{{refreshAnimation}}" src="/images/refreshpng"></image> 
 </view> 
<scroll-view scroll-y="true" style="height: {{windowHeight}}px;" bindscroll="scroll" bindscrolltolower="lower" bindscrolltoupper="upper" 
catchtouchmove="move" catchtouchstart="start" catchtouchend="end" 
> 
<block wx:for="{{words}}"> 
  <view class="item-style">{{itemname}}</view> 
</block> 
</scroll-view> 

3.index.wxss

/**indexwxss**/ 
item-style{ 
 padding: 30rpx; 
 font-size: 40rpx; 
 text-align: center; 
 border-top: 2rpx solid #eee; 
} 
refresh-block { 
 padding: 15px; 
 text-align: center 
} 
refresh-block image { 
 width: 30px; 
 height: 30px; 
} 

demo:下載地址
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 微信小程序仿RadioGroup改變樣式的處理方案

    微信小程序仿RadioGroup改變樣式的處理方案

    本文給大家分享一段簡單的代碼來實現(xiàn)微信小程序仿RadioGroup改變樣式的方法,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-07-07
  • ionic中的$ionicPlatform.ready事件中的通用設(shè)置

    ionic中的$ionicPlatform.ready事件中的通用設(shè)置

    $ionicPlatform.ready事件是用于檢測當前的平臺是否就緒的事件,相當于基于document的deviceready事件, 在app中一些通用關(guān)于設(shè)備的設(shè)置必須在這個事件中處理
    2017-06-06
  • JavaScript獲取一個范圍內(nèi)日期的方法

    JavaScript獲取一個范圍內(nèi)日期的方法

    這篇文章主要介紹了JavaScript獲取一個范圍內(nèi)日期的方法,涉及javascript操作日期的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • 淺析Bootstrap表格的使用

    淺析Bootstrap表格的使用

    Bootstrap - 簡潔、直觀、強悍、移動設(shè)備優(yōu)先的前端開發(fā)框架,讓web開發(fā)更迅速、簡單。下面給大家介紹Bootstrap表格的使用的相關(guān)知識,非常不錯,具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧
    2016-06-06
  • uniapp項目實踐自定義分享組件示例

    uniapp項目實踐自定義分享組件示例

    這篇文章主要為大家介紹了uniapp項目實踐自定義分享組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • javascript產(chǎn)生隨機數(shù)方法匯總

    javascript產(chǎn)生隨機數(shù)方法匯總

    這篇文章主要介紹了javascript產(chǎn)生隨機數(shù)方法匯總的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • JS加載器如何動態(tài)加載外部js文件

    JS加載器如何動態(tài)加載外部js文件

    這篇文章主要介紹了JS加載器如何動態(tài)加載外部js文件的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • 詳解JavaScript對象轉(zhuǎn)原始值

    詳解JavaScript對象轉(zhuǎn)原始值

    這篇文章主要為大家介紹了vue組件通信的幾種方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-12-12
  • javascript設(shè)計模式之module(模塊)模式

    javascript設(shè)計模式之module(模塊)模式

    這篇文章主要為大家詳細介紹了javascript設(shè)計模式之module(模塊)模式 ,感興趣的小伙伴們可以參考一下
    2016-08-08
  • CodeMirror js代碼加亮使用總結(jié)

    CodeMirror js代碼加亮使用總結(jié)

    一個基于JavaScript的代碼編輯器,CodeMirror支持大量語言的語法高亮,也包括css,html,js等的高亮顯示。此外,CodeMirror還支持代碼自動完成、搜索/替換、HTML預(yù)覽、行號、選擇/搜索結(jié)果高亮、可視化tab、代碼自動格式等
    2017-03-03

最新評論

呼和浩特市| 龙岩市| 河北省| 疏附县| 宁南县| 博兴县| 儋州市| 赞皇县| 连江县| 如东县| 南漳县| 武城县| 黄平县| 汽车| 汉源县| 左贡县| 子洲县| 海丰县| 西丰县| 望谟县| 深水埗区| 招远市| 南雄市| 新民市| 桂阳县| 耿马| 盘山县| 密山市| 邛崃市| 叙永县| 农安县| 深圳市| 沁源县| 湛江市| 屏南县| 磐石市| 抚宁县| 昭觉县| 姚安县| 宁波市| 酉阳|