微信小程序如何制作下拉刷新的动态效果?

更新于
2026-10-03 04:54:30
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1722个文字,预计阅读时间需要7分钟。

微信小程序动画下拉刷新代码示例:

javascript// 创建动画实例var animation=wx.createAnimation({ duration: 1000, timingFunction: 'ease',});

// 页面数据Page({ data: { animationData: {}, left1: Math.floor(Math.random() * 100), left2: Math.floor(Math.random() * 100), left3: Math.floor(Math.random() * 100), left4: Math.floor(Math.random() * 100), left5: Math.floor(Math.random() * 100), left6: Math.floor(Math.random() * 100), left7: Math.floor(Math.random() * 100), left8: Math.floor(Math.random() * 100), left9: Math.floor(Math.random() * 100), left10: Math.floor(Math.random() * 100), left11: Math.floor(Math.random() * 100), left12: Math.floor(Math.random() * 100), left13: Math.floor(Math.random() * 100), left14: Math.floor(Math.random() * 100), left15: Math.floor(Math.random() * 100), left16: Math.floor(Math.random() * 100), left17: Math.floor(Math.random() * 100), left18: Math.floor(Math.random() * 100), left19: Math.floor(Math.random() * 100), left20: Math.floor(Math.random() * 100), left21: Math.floor(Math.random() * 100), left22: Math.floor(Math.random() * 100), left23: Math.floor(Math.random() * 100), left24: Math.floor(Math.random() * 100), left25: Math.floor(Math.random() * 100), left26: Math.floor(Math.random() * 100), left27: Math.floor(Math.random() * 100), left28: Math.floor(Math.random() * 100), left29: Math.floor(Math.random() * 100), left30: Math.floor(Math.random() * 100), left31: Math.floor(Math.random() * 100), left32: Math.floor(Math.random() * 100), left33: Math.floor(Math.random() * 100), left34: Math.floor(Math.random() * 100), left35: Math.floor(Math.random() * 100), left36: Math.floor(Math.random() * 100), left37: Math.floor(Math.random() * 100), left38: Math.floor(Math.random() * 100), left39: Math.floor(Math.random() * 100), left40: Math.floor(Math.random() * 100), left41: Math.floor(Math.random() * 100), left42: Math.floor(Math.random() * 100), left43: Math.floor(Math.random() * 100), left44: Math.floor(Math.random() * 100), left45: Math.floor(Math.random() * 100), left46: Math.floor(Math.random() * 100), left47: Math.floor(Math.random() * 100), left48: Math.floor(Math.random() * 100), left49: Math.floor(Math.random() * 100), left50: Math.floor(Math.random() * 100), left51: Math.floor(Math.random() * 100), left52: Math.floor(Math.random() * 100), left53: Math.floor(Math.random() * 100), left54: Math.floor(Math.random() * 100), left55: Math.floor(Math.random() * 100), left56: Math.floor(Math.random() * 100), left57: Math.floor(Math.random() * 100), left58: Math.floor(Math.random() * 100), left59: Math.floor(Math.random() * 100), left60: Math.floor(Math.random() * 100), left61: Math.floor(Math.random() * 100), left62: Math.floor(Math.random() * 100), left63: Math.floor(Math.random() * 100), left64: Math.floor(Math.random() * 100), left65: Math.floor(Math.random() * 100), left66: Math.floor(Math.random() * 100), left67: Math.floor(Math.random() * 100), left68: Math.floor(Math.random() * 100), left69: Math.floor(Math.random() * 100), left70: Math.floor(Math.random() * 100), left71: Math.floor(Math.random() * 100), left72: Math.floor(Math.random() * 100), left73: Math.floor(Math.random() * 100), left74: Math.floor(Math.random() * 100), left75: Math.floor(Math.random() * 100), left76: Math.floor(Math.random() * 100), left77: Math.floor(Math.random() * 100), left78: Math.floor(Math.random() * 100), left79: Math.floor(Math.random() * 100), left80: Math.floor(Math.random() * 100), left81: Math.floor(Math.random() * 100), left82: Math.floor(Math.random() * 100), left83: Math.floor(Math.random() * 100), left84: Math.floor(Math.random() * 100), left85: Math.floor(Math.random() * 100), left86: Math.floor(Math.random() * 100), left87: Math.floor(Math.random() * 100), left88: Math.floor(Math.random() * 100), left89: Math.floor(Math.random() * 100), left90: Math.floor(Math.random() * 100), left91: Math.floor(Math.random() * 100), left92: Math.floor(Math.random() * 100), left93: Math.floor(Math.random() * 100), left94: Math.floor(Math.random() * 100), left95: Math.floor(Math.random() * 100), left96: Math.floor(Math.random() * 100), left97: Math.floor(Math.random() * 100), left98: Math.floor(Math.random() * 100), left99: Math.floor(Math.random() * 100), left100: Math.floor(Math.random() * 100), left101: Math.floor(Math.random() * 100), left102: Math.floor(Math.random() * 100), left103: Math.floor(Math.random() * 100), left104: Math.floor(Math.random() * 100), left105: Math.floor(Math.random() * 100), left106: Math.floor(Math.random() * 100), left107: Math.floor(Math.random() * 100), left108: Math.floor(Math.random() * 100), left109: Math.floor(Math.random() * 100), left110: Math.floor(Math.random() * 100), left111: Math.floor(Math.random() * 100), left112: Math.floor(Math.random() * 100), left113: Math.floor(Math.random() * 100), left114: Math.floor(Math.random() * 100), left115: Math.floor(Math.random() * 100), left116: Math.floor(Math.random() * 100), left117: Math.floor(Math.random() * 100), left118: Math.floor(Math.random() * 100), left119: Math.floor(Math.random() * 100), left120: Math.floor(Math.random() * 100), left121: Math.floor(Math.random() * 100), left122: Math.floor(Math.random() * 100), left123: Math.floor(Math.random() * 100), left124: Math.floor(Math.random() * 100), left125: Math.floor(Math.random() * 100), left126: Math.floor(Math.random() * 100), left127: Math.floor(Math.random() * 100), left128: Math.floor(Math.random() * 100), left129: Math.floor(Math.random() * 100), left130: Math.floor(Math.random() * 100), left131: Math.floor(Math.random() * 100), left132: Math.floor(Math.random() * 100), left133: Math.floor(Math.random() * 100), left134: Math.floor(Math.random() * 100), left135: Math.floor(Math.random() * 100), left136: Math.floor(Math.random() * 100), left137: Math.floor(Math.random() * 100), left138: Math.floor(Math.random() * 100), left139: Math.floor(Math.random() * 100), left140: Math.floor(Math.random() * 100), left141: Math.floor(Math.random() * 100), left142: Math.floor(Math.random() * 100), left143: Math.floor(Math.random() * 100), left144: Math.floor(Math.random() * 100), left145: Math.floor(Math.random() * 100), left146: Math.floor(Math.random() * 100), left147: Math.floor(Math.random() * 100), left148: Math.floor(Math.random() * 100), left149: Math.floor(Math.random() * 100), left150: Math.floor(Math.random() * 100), left151: Math.floor(Math.random() * 100), left152: Math.floor(Math.random() * 100), left153: Math.floor(Math.random() * 100), left154: Math.floor(Math.random() * 100), left155: Math.floor(Math.random() * 100), left156: Math.floor(Math.random() * 100), left157: Math.floor(Math.random() * 100), left158: Math.floor(Math.random() * 100), left159: Math.floor(Math.random() * 100), left160: Math.floor(Math.random() * 100), left161: Math.floor(Math.random() * 100), left162: Math.floor(Math.random() * 100), left163: Math.floor(Math.random() * 100), left164: Math.floor(Math.random() * 100), left165: Math.floor(Math.random() * 100), left166: Math.floor(Math.random() * 100), left167: Math.floor(Math.random() * 100), left168: Math.floor(Math.random() * 100), left169: Math.floor(Math.random() * 100), left170: Math.floor(Math.random() * 100), left171: Math.floor(Math.random() * 100), left172: Math.floor(Math.random() * 100), left173: Math.floor(Math.random() * 100), left174: Math.floor(Math.random() * 100), left175: Math.floor(Math.random() * 100), left176: Math.floor(Math.random() * 100), left177: Math.floor(Math.random() * 100), left178: Math.floor(Math.random() * 100), left179: Math.floor(Math.random() * 100), left180: Math.floor(Math.random() * 100), left181: Math.floor(Math.random() * 100), left182: Math.floor(Math.random() * 100), left183: Math.floor(Math.random() * 100), left184: Math.floor(Math.random() * 100), left185: Math.floor(Math.random() * 100), left186: Math.floor(Math.random() * 100), left187: Math.floor(Math.random() * 100), left188: Math.floor(Math.random() * 100), left189: Math.floor(Math.random() * 100), left190: Math.floor(Math.random() * 100), left191: Math.floor(Math.random() * 100), left192: Math.floor(Math.random() * 100), left193: Math.floor(Math.random() * 100), left194: Math.floor(Math.random() * 100), left195: Math.floor(Math.random() * 100), left196: Math.floor(Math.random() * 100), left197: Math.floor(Math.random() * 100), left198: Math.floor(Math.random() * 100), left199: Math.floor(Math.random() * 100), left200: Math.floor(Math.random() * 100), },

// 动画效果 onPullDownRefresh: function () { var that=this; animation.translateY(-100).step(); that.setData({ animationData: animation.export() });

setTimeout(function () { animation.translateY(0).step(); that.setData({ animationData: animation.export() }); }, 1000);

wx.stopPullDownRefresh(); }});

微信小程序动画之下拉刷新动画的具体代码,供大家参考,具体内容如下

简易的效果

下面放代码:

js:

var animation = wx.createAnimation({}) var i = 1; Page({ data: { donghua: true, left1: Math.floor(Math.random() * 250 + 1), left2: Math.floor(Math.random() * 250 + 1), left3: Math.floor(Math.random() * 250 + 1), left4: Math.floor(Math.random() * 250 + 1), left5: Math.floor(Math.random() * 250 + 1), left6: Math.floor(Math.random() * 250 + 1), left7: Math.floor(Math.random() * 250 + 1), left8: Math.floor(Math.random() * 250 + 1), }, //动画 donghua: function () { var that = this; setTimeout(function () { animation.translateY(800).step({ duration: 1600, timingFunction: 'ease' }) that.setData({ ["animationData" + i]: animation.export() }) i++; }.bind(that), 200) if (i < 9) { setTimeout(function () { that.donghua() }.bind(that), 200) } else { i = 0; animation.translateY(-800).step({ duration: 10, }) setTimeout(function () { for (var y = 0; y < 9; y++) { that.setData({ ["animationData" + y]: animation.export() }) that.setData({ ["animationData" + y + '.actions[0].animates[0].args[0]']: 0 }) } }.bind(that), 1500) } }, onPullDownRefresh: function () { wx.showNavigationBarLoading(); this.donghua(); wx.stopPullDownRefresh(); }, })

wxml:

<!-- 动画 --> <block wx:if="{{donghua}}"> <view class='donghua'> <image bindtap='hua' style='left:{{left1}}px' animation="{{animationData1}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left2}}px' animation="{{animationData2}}" src='../../images/2.png'></image> <image bindtap='hua' style='left:{{left3}}px' animation="{{animationData3}}" src='../../images/3.png'></image> <image bindtap='hua' style='left:{{left4}}px' animation="{{animationData4}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left5}}px' animation="{{animationData5}}" src='../../images/2.png'></image> <image bindtap='hua' style='left:{{left6}}px' animation="{{animationData6}}" src='../../images/3.png'></image> <image bindtap='hua' style='left:{{left7}}px' animation="{{animationData7}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left8}}px' animation="{{animationData8}}" src='../../images/2.png'></image> </view> </block>

wxss:

image{ margin-top: -150rpx; width: 40rpx; height: 40rpx; margin-left: 5%; position: absolute; }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。

本文共计1722个文字,预计阅读时间需要7分钟。

微信小程序动画下拉刷新代码示例:

javascript// 创建动画实例var animation=wx.createAnimation({ duration: 1000, timingFunction: 'ease',});

// 页面数据Page({ data: { animationData: {}, left1: Math.floor(Math.random() * 100), left2: Math.floor(Math.random() * 100), left3: Math.floor(Math.random() * 100), left4: Math.floor(Math.random() * 100), left5: Math.floor(Math.random() * 100), left6: Math.floor(Math.random() * 100), left7: Math.floor(Math.random() * 100), left8: Math.floor(Math.random() * 100), left9: Math.floor(Math.random() * 100), left10: Math.floor(Math.random() * 100), left11: Math.floor(Math.random() * 100), left12: Math.floor(Math.random() * 100), left13: Math.floor(Math.random() * 100), left14: Math.floor(Math.random() * 100), left15: Math.floor(Math.random() * 100), left16: Math.floor(Math.random() * 100), left17: Math.floor(Math.random() * 100), left18: Math.floor(Math.random() * 100), left19: Math.floor(Math.random() * 100), left20: Math.floor(Math.random() * 100), left21: Math.floor(Math.random() * 100), left22: Math.floor(Math.random() * 100), left23: Math.floor(Math.random() * 100), left24: Math.floor(Math.random() * 100), left25: Math.floor(Math.random() * 100), left26: Math.floor(Math.random() * 100), left27: Math.floor(Math.random() * 100), left28: Math.floor(Math.random() * 100), left29: Math.floor(Math.random() * 100), left30: Math.floor(Math.random() * 100), left31: Math.floor(Math.random() * 100), left32: Math.floor(Math.random() * 100), left33: Math.floor(Math.random() * 100), left34: Math.floor(Math.random() * 100), left35: Math.floor(Math.random() * 100), left36: Math.floor(Math.random() * 100), left37: Math.floor(Math.random() * 100), left38: Math.floor(Math.random() * 100), left39: Math.floor(Math.random() * 100), left40: Math.floor(Math.random() * 100), left41: Math.floor(Math.random() * 100), left42: Math.floor(Math.random() * 100), left43: Math.floor(Math.random() * 100), left44: Math.floor(Math.random() * 100), left45: Math.floor(Math.random() * 100), left46: Math.floor(Math.random() * 100), left47: Math.floor(Math.random() * 100), left48: Math.floor(Math.random() * 100), left49: Math.floor(Math.random() * 100), left50: Math.floor(Math.random() * 100), left51: Math.floor(Math.random() * 100), left52: Math.floor(Math.random() * 100), left53: Math.floor(Math.random() * 100), left54: Math.floor(Math.random() * 100), left55: Math.floor(Math.random() * 100), left56: Math.floor(Math.random() * 100), left57: Math.floor(Math.random() * 100), left58: Math.floor(Math.random() * 100), left59: Math.floor(Math.random() * 100), left60: Math.floor(Math.random() * 100), left61: Math.floor(Math.random() * 100), left62: Math.floor(Math.random() * 100), left63: Math.floor(Math.random() * 100), left64: Math.floor(Math.random() * 100), left65: Math.floor(Math.random() * 100), left66: Math.floor(Math.random() * 100), left67: Math.floor(Math.random() * 100), left68: Math.floor(Math.random() * 100), left69: Math.floor(Math.random() * 100), left70: Math.floor(Math.random() * 100), left71: Math.floor(Math.random() * 100), left72: Math.floor(Math.random() * 100), left73: Math.floor(Math.random() * 100), left74: Math.floor(Math.random() * 100), left75: Math.floor(Math.random() * 100), left76: Math.floor(Math.random() * 100), left77: Math.floor(Math.random() * 100), left78: Math.floor(Math.random() * 100), left79: Math.floor(Math.random() * 100), left80: Math.floor(Math.random() * 100), left81: Math.floor(Math.random() * 100), left82: Math.floor(Math.random() * 100), left83: Math.floor(Math.random() * 100), left84: Math.floor(Math.random() * 100), left85: Math.floor(Math.random() * 100), left86: Math.floor(Math.random() * 100), left87: Math.floor(Math.random() * 100), left88: Math.floor(Math.random() * 100), left89: Math.floor(Math.random() * 100), left90: Math.floor(Math.random() * 100), left91: Math.floor(Math.random() * 100), left92: Math.floor(Math.random() * 100), left93: Math.floor(Math.random() * 100), left94: Math.floor(Math.random() * 100), left95: Math.floor(Math.random() * 100), left96: Math.floor(Math.random() * 100), left97: Math.floor(Math.random() * 100), left98: Math.floor(Math.random() * 100), left99: Math.floor(Math.random() * 100), left100: Math.floor(Math.random() * 100), left101: Math.floor(Math.random() * 100), left102: Math.floor(Math.random() * 100), left103: Math.floor(Math.random() * 100), left104: Math.floor(Math.random() * 100), left105: Math.floor(Math.random() * 100), left106: Math.floor(Math.random() * 100), left107: Math.floor(Math.random() * 100), left108: Math.floor(Math.random() * 100), left109: Math.floor(Math.random() * 100), left110: Math.floor(Math.random() * 100), left111: Math.floor(Math.random() * 100), left112: Math.floor(Math.random() * 100), left113: Math.floor(Math.random() * 100), left114: Math.floor(Math.random() * 100), left115: Math.floor(Math.random() * 100), left116: Math.floor(Math.random() * 100), left117: Math.floor(Math.random() * 100), left118: Math.floor(Math.random() * 100), left119: Math.floor(Math.random() * 100), left120: Math.floor(Math.random() * 100), left121: Math.floor(Math.random() * 100), left122: Math.floor(Math.random() * 100), left123: Math.floor(Math.random() * 100), left124: Math.floor(Math.random() * 100), left125: Math.floor(Math.random() * 100), left126: Math.floor(Math.random() * 100), left127: Math.floor(Math.random() * 100), left128: Math.floor(Math.random() * 100), left129: Math.floor(Math.random() * 100), left130: Math.floor(Math.random() * 100), left131: Math.floor(Math.random() * 100), left132: Math.floor(Math.random() * 100), left133: Math.floor(Math.random() * 100), left134: Math.floor(Math.random() * 100), left135: Math.floor(Math.random() * 100), left136: Math.floor(Math.random() * 100), left137: Math.floor(Math.random() * 100), left138: Math.floor(Math.random() * 100), left139: Math.floor(Math.random() * 100), left140: Math.floor(Math.random() * 100), left141: Math.floor(Math.random() * 100), left142: Math.floor(Math.random() * 100), left143: Math.floor(Math.random() * 100), left144: Math.floor(Math.random() * 100), left145: Math.floor(Math.random() * 100), left146: Math.floor(Math.random() * 100), left147: Math.floor(Math.random() * 100), left148: Math.floor(Math.random() * 100), left149: Math.floor(Math.random() * 100), left150: Math.floor(Math.random() * 100), left151: Math.floor(Math.random() * 100), left152: Math.floor(Math.random() * 100), left153: Math.floor(Math.random() * 100), left154: Math.floor(Math.random() * 100), left155: Math.floor(Math.random() * 100), left156: Math.floor(Math.random() * 100), left157: Math.floor(Math.random() * 100), left158: Math.floor(Math.random() * 100), left159: Math.floor(Math.random() * 100), left160: Math.floor(Math.random() * 100), left161: Math.floor(Math.random() * 100), left162: Math.floor(Math.random() * 100), left163: Math.floor(Math.random() * 100), left164: Math.floor(Math.random() * 100), left165: Math.floor(Math.random() * 100), left166: Math.floor(Math.random() * 100), left167: Math.floor(Math.random() * 100), left168: Math.floor(Math.random() * 100), left169: Math.floor(Math.random() * 100), left170: Math.floor(Math.random() * 100), left171: Math.floor(Math.random() * 100), left172: Math.floor(Math.random() * 100), left173: Math.floor(Math.random() * 100), left174: Math.floor(Math.random() * 100), left175: Math.floor(Math.random() * 100), left176: Math.floor(Math.random() * 100), left177: Math.floor(Math.random() * 100), left178: Math.floor(Math.random() * 100), left179: Math.floor(Math.random() * 100), left180: Math.floor(Math.random() * 100), left181: Math.floor(Math.random() * 100), left182: Math.floor(Math.random() * 100), left183: Math.floor(Math.random() * 100), left184: Math.floor(Math.random() * 100), left185: Math.floor(Math.random() * 100), left186: Math.floor(Math.random() * 100), left187: Math.floor(Math.random() * 100), left188: Math.floor(Math.random() * 100), left189: Math.floor(Math.random() * 100), left190: Math.floor(Math.random() * 100), left191: Math.floor(Math.random() * 100), left192: Math.floor(Math.random() * 100), left193: Math.floor(Math.random() * 100), left194: Math.floor(Math.random() * 100), left195: Math.floor(Math.random() * 100), left196: Math.floor(Math.random() * 100), left197: Math.floor(Math.random() * 100), left198: Math.floor(Math.random() * 100), left199: Math.floor(Math.random() * 100), left200: Math.floor(Math.random() * 100), },

// 动画效果 onPullDownRefresh: function () { var that=this; animation.translateY(-100).step(); that.setData({ animationData: animation.export() });

setTimeout(function () { animation.translateY(0).step(); that.setData({ animationData: animation.export() }); }, 1000);

wx.stopPullDownRefresh(); }});

微信小程序动画之下拉刷新动画的具体代码,供大家参考,具体内容如下

简易的效果

下面放代码:

js:

var animation = wx.createAnimation({}) var i = 1; Page({ data: { donghua: true, left1: Math.floor(Math.random() * 250 + 1), left2: Math.floor(Math.random() * 250 + 1), left3: Math.floor(Math.random() * 250 + 1), left4: Math.floor(Math.random() * 250 + 1), left5: Math.floor(Math.random() * 250 + 1), left6: Math.floor(Math.random() * 250 + 1), left7: Math.floor(Math.random() * 250 + 1), left8: Math.floor(Math.random() * 250 + 1), }, //动画 donghua: function () { var that = this; setTimeout(function () { animation.translateY(800).step({ duration: 1600, timingFunction: 'ease' }) that.setData({ ["animationData" + i]: animation.export() }) i++; }.bind(that), 200) if (i < 9) { setTimeout(function () { that.donghua() }.bind(that), 200) } else { i = 0; animation.translateY(-800).step({ duration: 10, }) setTimeout(function () { for (var y = 0; y < 9; y++) { that.setData({ ["animationData" + y]: animation.export() }) that.setData({ ["animationData" + y + '.actions[0].animates[0].args[0]']: 0 }) } }.bind(that), 1500) } }, onPullDownRefresh: function () { wx.showNavigationBarLoading(); this.donghua(); wx.stopPullDownRefresh(); }, })

wxml:

<!-- 动画 --> <block wx:if="{{donghua}}"> <view class='donghua'> <image bindtap='hua' style='left:{{left1}}px' animation="{{animationData1}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left2}}px' animation="{{animationData2}}" src='../../images/2.png'></image> <image bindtap='hua' style='left:{{left3}}px' animation="{{animationData3}}" src='../../images/3.png'></image> <image bindtap='hua' style='left:{{left4}}px' animation="{{animationData4}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left5}}px' animation="{{animationData5}}" src='../../images/2.png'></image> <image bindtap='hua' style='left:{{left6}}px' animation="{{animationData6}}" src='../../images/3.png'></image> <image bindtap='hua' style='left:{{left7}}px' animation="{{animationData7}}" src='../../images/1.png'></image> <image bindtap='hua' style='left:{{left8}}px' animation="{{animationData8}}" src='../../images/2.png'></image> </view> </block>

wxss:

image{ margin-top: -150rpx; width: 40rpx; height: 40rpx; margin-left: 5%; position: absolute; }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。