本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)動(dòng)態(tài)列表項(xiàng)的順序加載動(dòng)畫(huà),供大家參考,具體內(nèi)容如下
效果

思路
1、最開(kāi)始用了純CSS動(dòng)畫(huà)animation,發(fā)現(xiàn)動(dòng)畫(huà)需要重復(fù)寫(xiě),于是換使用transition動(dòng)畫(huà)。
2、使用onReady()可以讓頁(yè)面加載好再顯示動(dòng)畫(huà)以免動(dòng)畫(huà)提前結(jié)束。
代碼
wxml
<!-- style中的主要為了區(qū)分已加載好的項(xiàng)和新數(shù)據(jù),只有新數(shù)據(jù)有動(dòng)畫(huà) --><view wx:for="{{lists}}" class="common" style='opacity:{{index >= (page-1)*2?op:"1"}};margin-left:{{index >= (page-1)*2?mr:"0"}}rpx;transition:all {{index >= (page-1)*2?(index-(page-1)*2)*0.5+0.5:"0"}}s;' > 第{{index}}條</view> <view bindtap='next' style='position:relative;right:-150px;top:50rpx;'>下一頁(yè)</view>wcss
page{ background: #eee}.common{ height: 100rpx; opacity: 0; margin-left: -50rpx; background: #fff; margin-top: 20rpx; line-height: 100rpx; padding: 25rpx;}js
Page({ data: { list: ['啦啦啦', '嚯嚯嚯'], lists: ['啦啦啦', '嚯嚯嚯'], page:1 }, onLoad: function (options) { }, onReady:function(e){ this.setData({ op: 1, mr:0 }) }, next:function(e){ this.data.page ++; //模擬從后臺(tái)獲取到了下一頁(yè)的數(shù)據(jù),附加到原有數(shù)組上 var lists = this.data.lists.concat(this.data.list) this.setData({ lists:lists, page: this.data.page, op: 0, mr: -50 }) this.onReady(); },})以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注