小程序菜單按鈕向左彈出動(dòng)畫的實(shí)現(xiàn)

需求:實(shí)現(xiàn)一個(gè)點(diǎn)擊菜單懸浮按鈕氨距,向左彈出子菜單的動(dòng)畫

最終效果展示:
開始狀態(tài).png

彈出狀態(tài).png

需求分析:這里一共有6個(gè)動(dòng)畫效果无埃,其中包括:主菜單按鈕、4個(gè)子菜單按鈕(動(dòng)畫效果類似)铣焊、和背景動(dòng)畫效果。

主菜單按鈕動(dòng)畫:實(shí)現(xiàn).rotateZ從 Z 軸順時(shí)針旋轉(zhuǎn)一個(gè)角度動(dòng)畫
4個(gè)子菜單按鈕動(dòng)畫:實(shí)現(xiàn)translate平移動(dòng)畫
背景圖動(dòng)畫:實(shí)現(xiàn)translate平移動(dòng)畫罕伯、并且動(dòng)態(tài)設(shè)置背景寬度

分析完了曲伊,下面是具體代碼:
js代碼:

// components/Menu/menu.js
var systemInfo = wx.getSystemInfoSync();
Component({
  lifetimes: {
    attached: function () {
      // 在組件實(shí)例進(jìn)入頁(yè)面節(jié)點(diǎn)樹時(shí)執(zhí)行
      this.setData({
        systemInfo: systemInfo

      })
    },
    detached: function () {
      // 在組件實(shí)例被從頁(yè)面節(jié)點(diǎn)樹移除時(shí)執(zhí)行
    },
  },
  /**
   * 組件的屬性列表
   */
  properties: {

  },

  /**
   * 組件的初始數(shù)據(jù)
   */
  data: {
    isShow: false,//是否已經(jīng)彈出
    animMain: {},//旋轉(zhuǎn)動(dòng)畫
    animImg: {},//原始影像動(dòng)畫
    animMedicalhistory: {},// 病歷文書動(dòng)畫
    animInspection:{},//檢驗(yàn)報(bào)告動(dòng)畫
    animcheck:{},//檢查報(bào)告動(dòng)畫
    animItem:{},//圖標(biāo)背景動(dòng)畫
    animTime: 300,//動(dòng)畫持續(xù)時(shí)間,單位 ms
    timingFunction_start: 'ease-out',//動(dòng)畫的效果
    timingFunction_end: 'ease-out'//動(dòng)畫的效果


  },

  /**
   * 組件的方法列表
   */
  methods: {
    //點(diǎn)擊彈出或者收起
    showOrHide: function () {
      if (this.data.isShow) {
        //縮回動(dòng)畫
        this.takeback();
        this.setData({
          isShow: false,

        })
      } else {
        //彈出動(dòng)畫
        this.popp();
        this.setData({
          isShow: true,

        })
      }
    },
    img: function () {
      this.triggerEvent("img")
      this.showOrHide()
    },
    medicalhistory: function () {
      this.triggerEvent("medicalhistory")
      this.showOrHide()
    },

    inspection: function () {
      this.triggerEvent("inspection")
      this.showOrHide()
    },
    check: function () {
      this.triggerEvent("check")
      this.showOrHide()
    },
    //彈出動(dòng)畫
    popp: function () {
      //main按鈕順時(shí)針旋轉(zhuǎn)
      var animationMain = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })
      var animationMedicalhistory = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })
      var animationImg = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })

      var animationInspection = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })

      var animationCheck = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })

      var animationItem= wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_start
      })


      animationMain.rotateZ(180).step();
      animationCheck.translate(-systemInfo.windowWidth /2, 0).step();
      animationInspection.translate(-systemInfo.windowWidth / 2.5, 0).step();
      animationMedicalhistory.translate(-systemInfo.windowWidth/3.5, 0).step();
      animationImg.translate(-systemInfo.windowWidth/6, 0).step();

      animationItem.translate(-systemInfo.windowWidth / 7, 0).width(systemInfo.windowWidth / 2).step();

      this.setData({
        animMain: animationMain.export(),
        animMedicalhistory: animationMedicalhistory.export(),
        animImg: animationImg.export(),
        animInspection: animationInspection.export(),
        animCheck: animationCheck.export(),
        animItem: animationItem.export(),



      })
    },
    //收回動(dòng)畫
    takeback: function () {
      //main按鈕逆時(shí)針旋轉(zhuǎn)
      var animationMain = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })
      var animationMedicalhistory = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })
      var animationImg = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })
      var animationInspection = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })
      var animationCheck = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })
      var animationItem = wx.createAnimation({
        duration: this.data.animTime,
        timingFunction: this.data.timingFunction_end
      })

      animationMain.rotateZ(0).step();
      animationCheck.translate(0, 0).rotateZ(0).step();
      animationInspection.translate(0, 0).rotateZ(0).step();
      animationMedicalhistory.translate(0, 0).rotateZ(0).step();
      animationImg.translate(0, 0).rotateZ(0).step();
      animationItem.translate(0, 0).width(-systemInfo.windowWidth).step();

      this.setData({
        animMain: animationMain.export(),
        animMedicalhistory: animationMedicalhistory.export(),
        animImg: animationImg.export(),
        animInspection: animationInspection.export(),
        animCheck: animationCheck.export(),
        animItem: animationItem.export(),

      })
    }
  },
  //解決滾動(dòng)穿透問題
  myCatchTouch: function () {
    return
  }
})

wxml代碼:

<view class="drawer_screen" bindtap="showOrHide" wx:if="{{isShow}}" catchtouchmove="myCatchTouch"></view>
<view>
  <view class="item-class"  animation="{{animItem}}"></view>

<image src="../../images/icon/imgdetails_icon_check@2x.png" class="buttom" animation="{{animCheck}}" bindtap="check"></image>
<image src="../../images/icon/imgdetails_icon_inspection@2x.png" class="buttom" animation="{{animInspection}}" bindtap="inspection"></image>
    <image src="../../images/icon/imgdetails_icon_medicalhistory@2x.png" class="buttom" animation="{{animMedicalhistory}}" bindtap="medicalhistory"></image>
    <image src="../../images/icon/imgdetails_icon_img@2x.png" class="buttom" animation="{{animImg}}" bindtap="img"></image>
    <image src="../../images/icon/imgdetails_icon_menu@2x.png" class="main-buttom" animation="{{animMain}}" bindtap="showOrHide"></image>
</view>

wxss代碼:

/* components/menu/index.wxss */
.main-buttom{
  width: 100rpx;
  height: 100rpx;
  display: flex;
  flex-direction: row;
  position: fixed;
  bottom:220rpx;
  right: 60rpx;
  z-index: 1001;
}
.buttom{
  width: 50rpx;
  height: 50rpx;
  display: flex;
  flex-direction: row;
  position: fixed;
  bottom:244rpx;
  right: 80rpx;
  z-index: 1001;
}
.drawer_screen {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right:0;
  bottom:0;
  z-index: 1000;
  background: #000;
  opacity: 0;
  overflow: hidden;
}
.drawer_box {
  overflow: hidden;
  position: fixed;
  z-index: 1001;
}


.item-class {
position: fixed;
bottom: 225rpx;
right: 60rpx;
background: white;
border: 1px solid white;
border-radius: 40rpx;
box-shadow: 0px 0px 30px rgba(0, 0, 0, 0.1);
height: 85rpx;

}

page頁(yè)面調(diào)用:

  <menu hidden id='menu' 
       bind:img="onImg" 
       bind:medicalhistory="onMedicalhistory" 
       bind:inspection="onInspection"
       bind:check="onCheck" />
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末追他,一起剝皮案震驚了整個(gè)濱河市坟募,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌邑狸,老刑警劉巖懈糯,帶你破解...
    沈念sama閱讀 212,454評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異单雾,居然都是意外死亡赚哗,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門硅堆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來屿储,“玉大人,你說我怎么就攤上這事渐逃」宦樱” “怎么了?”我有些...
    開封第一講書人閱讀 157,921評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵茄菊,是天一觀的道長(zhǎng)疯潭。 經(jīng)常有香客問我赊堪,道長(zhǎng),這世上最難降的妖魔是什么竖哩? 我笑而不...
    開封第一講書人閱讀 56,648評(píng)論 1 284
  • 正文 為了忘掉前任雹食,我火速辦了婚禮,結(jié)果婚禮上期丰,老公的妹妹穿的比我還像新娘。我一直安慰自己吃挑,他們只是感情好钝荡,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評(píng)論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著舶衬,像睡著了一般埠通。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上逛犹,一...
    開封第一講書人閱讀 49,950評(píng)論 1 291
  • 那天端辱,我揣著相機(jī)與錄音,去河邊找鬼虽画。 笑死舞蔽,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的码撰。 我是一名探鬼主播渗柿,決...
    沈念sama閱讀 39,090評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼脖岛!你這毒婦竟也來了朵栖?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,817評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤柴梆,失蹤者是張志新(化名)和其女友劉穎陨溅,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绍在,經(jīng)...
    沈念sama閱讀 44,275評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡门扇,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了揣苏。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片悯嗓。...
    茶點(diǎn)故事閱讀 38,724評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖卸察,靈堂內(nèi)的尸體忽然破棺而出脯厨,到底是詐尸還是另有隱情,我是刑警寧澤坑质,帶...
    沈念sama閱讀 34,409評(píng)論 4 333
  • 正文 年R本政府宣布合武,位于F島的核電站临梗,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏稼跳。R本人自食惡果不足惜盟庞,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評(píng)論 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望汤善。 院中可真熱鬧什猖,春花似錦、人聲如沸红淡。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)在旱。三九已至摇零,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間桶蝎,已是汗流浹背驻仅。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留登渣,地道東北人噪服。 一個(gè)月前我還...
    沈念sama閱讀 46,503評(píng)論 2 361
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像绍豁,于是被迫代替她去往敵國(guó)和親芯咧。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容

  • 【Android 動(dòng)畫】 動(dòng)畫分類補(bǔ)間動(dòng)畫(Tween動(dòng)畫)幀動(dòng)畫(Frame 動(dòng)畫)屬性動(dòng)畫(Property ...
    Rtia閱讀 6,119評(píng)論 1 38
  • 看了很多視頻竹揍、文章敬飒,最后卻通通忘記了,別人的知識(shí)依舊是別人的芬位,自己卻什么都沒獲得无拗。此系列文章旨在加深自己的印象,因...
    DCbryant閱讀 1,857評(píng)論 0 4
  • 最近一個(gè)月都在做微信小程序昧碉,作為一個(gè)Android開發(fā)者英染,在這一個(gè)月很少寫Android的代碼,真是悲催被饿,好在現(xiàn)在...
    Code4Android閱讀 7,930評(píng)論 4 13
  • 前情回顧 我和喬?hào)|是通過前同事唐志軍認(rèn)識(shí)的四康,那時(shí)候我剛到現(xiàn)在這家公司,實(shí)在無法忍受租住的地下室了狭握,就詢問有沒有認(rèn)識(shí)...
    狗一樣的污姐閱讀 255評(píng)論 1 2
  • 迭代器 可用于集合闪金,列表,元組,字典哎垦,字符串 可以用于節(jié)省內(nèi)存囱嫩,用完一個(gè)數(shù)據(jù)就可以del掉 可循環(huán)的對(duì)象統(tǒng)稱為:I...
    Luo_Luo閱讀 253評(píng)論 0 0