国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

微信小程序圖片左右擺動效果詳解

2019-11-19 11:11:15
字體:
來源:轉載
供稿:網友

先看效果,實現一個圖片左右搖動,在一般的H5宣傳頁,商家活動頁面我們會看到這樣的動畫,小程序的動畫效果不同于css3動畫效果,是通過js來完成的,其實步驟很簡單,首先創建動畫實例,再調用實例來描述動畫,最后導出即可。

先看效果如下:

簡單的參考代碼:

wxml:

<image class='img' src="http://intmote.com/picture/gift.png" animation="{{animation}}"></image>

css:

.img { width: 120rpx; height: 120rpx; margin:300rpx;}

js

Page({ data: {  animation: {}, }, onLoad: function () { }, onShow: function () {  // 1: 創建動畫實例animation:  var animation = wx.createAnimation({   duration: 500,   timingFunction: 'ease',  })  this.animation = animation  var next = true;  //連續動畫關鍵步驟  setInterval(function () {   //2: 調用動畫實例方法來描述動畫   if (next) {    animation.translateX(4).step();    animation.rotate(19).step()    next = !next;   } else {    animation.translateX(-4).step();    animation.rotate(-19).step()    next = !next;   }   //3: 將動畫export導出,把動畫數據傳遞組件animation的屬性    this.setData({    animation: animation.export()   })  }.bind(this), 300) },})

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 利辛县| 民勤县| 高陵县| 德昌县| 共和县| 永新县| 三河市| 阿合奇县| 安泽县| 资阳市| 耒阳市| 葫芦岛市| 宁安市| 江达县| 乐亭县| 资兴市| 黄大仙区| 仪征市| 天津市| 绿春县| 油尖旺区| 大庆市| 南郑县| 奎屯市| 汤阴县| 关岭| 富源县| 衢州市| 蒙自县| 德安县| 东乡族自治县| 绥滨县| 攀枝花市| 雷波县| 灌阳县| 柘荣县| 江西省| 梧州市| 铜陵市| 竹溪县| 中牟县|