微信小程序动画之弹出菜单

用微信小程序做了一个动画,效果如上图:

代码:

js:

Page({
  data: {
    isPopping: false,
    animPlus: {},
    animCollect: {},
    animTranspond: {},
    animInput: {},
    animCloud:{},
    aninWrite:{},
  },
  //点击弹出
  plus: function () {
    if (this.data.isPopping) {
      //缩回动画
      this.popp();
      this.setData({
        isPopping: false
      })
    } else if (!this.data.isPopping) {
      //弹出动画
      this.takeback();
      this.setData({
        isPopping: true
      })
    }
  },
  input: function () {
    console.log("input")
  },
  transpond: function () {
    console.log("transpond")
  },
  collect: function () {
    console.log("collect")
  },
  cloud:function(){
    console.log("cloud")
  },
  write: function () {
    console.log("cloud")
  },

  //弹出动画
  popp: function () {
    //plus顺时针旋转
    var animationPlus = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationcollect = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationTranspond = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationInput = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationCloud = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationWrite = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    animationPlus.rotateZ(180).step();
    animationcollect.translate(-90, -100).rotateZ(180).opacity(1).step();
    animationTranspond.translate(-140, 0).rotateZ(180).opacity(1).step();
    animationInput.translate(-90, 100).rotateZ(180).opacity(1).step();
    animationCloud.translate(0, 135).rotateZ(180).opacity(1).step();
    animationWrite.translate(0, -135).rotateZ(180).opacity(1).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
      animCloud: animationCloud.export(),
      animWrite: animationWrite.export(),
    })
  },
  //收回动画
  takeback: function () {
    //plus逆时针旋转
    var animationPlus = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationcollect = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationTranspond = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationInput = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationCloud = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    var animationWrite = wx.createAnimation({
      duration: 400,
      timingFunction: ‘ease-out‘
    })
    animationPlus.rotateZ(0).step();
    animationcollect.translate(0, 0).rotateZ(0).opacity(0).step();
    animationTranspond.translate(0, 0).rotateZ(0).opacity(0).step();
    animationInput.translate(0, 0).rotateZ(0).opacity(0).step();
    animationCloud.translate(0, 0).rotateZ(0).opacity(0).step();
    animationWrite.translate(0, 0).rotateZ(0).opacity(0).step();
    this.setData({
      animPlus: animationPlus.export(),
      animCollect: animationcollect.export(),
      animTranspond: animationTranspond.export(),
      animInput: animationInput.export(),
      animCloud: animationCloud.export(),
      animWrite: animationWrite.export(),
    })
  },

  onLoad: function (options) {
    // 生命周期函数--监听页面加载
  },
  onReady: function () {
    // 生命周期函数--监听页面初次渲染完成
  },
  onShow: function () {
    // 生命周期函数--监听页面显示
  },
  onHide: function () {
    // 生命周期函数--监听页面隐藏
  },
  onUnload: function () {
    // 生命周期函数--监听页面卸载
  },
  onPullDownRefresh: function () {
    // 页面相关事件处理函数--监听用户下拉动作
  },
  onReachBottom: function () {
    // 页面上拉触底事件的处理函数
  },
  onShareAppMessage: function () {
    // 用户点击右上角分享
    return {
      title: ‘title‘, // 分享标题
      desc: ‘desc‘, // 分享描述
      path: ‘path‘ // 分享路径
    }
  }
})

wxml:

<view>
  <image src="../../image/1.png" class="img-style" animation="{{animWrite}}" bindtap="write"></image>
  <image src="../../image/4.png" class="img-style" animation="{{animCollect}}" bindtap="collect"></image>
  <image src="../../image/2.png" class="img-style" animation="{{animTranspond}}" bindtap="transpond"></image>
  <image src="../../image/3.png" class="img-style" animation="{{animInput}}" bindtap="input"></image>
  <image src="../../image/5.png" class="img-style" animation="{{animCloud}}" bindtap="cloud"></image>
  <image src="../../image/6.png" class="img-switch-style" animation="{{animPlus}}" bindtap="plus"></image>
</view>

  

wxss:

.img-switch-style {
  height: 120rpx;
  width: 120rpx;
  position: absolute;
  bottom: 250rpx;
  right: 100rpx;
  z-index: 100;
}

.img-style {
  height: 120rpx;
  width: 120rpx;
  position: absolute;
  bottom: 250rpx;
  right: 100rpx;
  opacity: 0;
}

  

原文地址:https://www.cnblogs.com/CodeHunter-qcy/p/11277986.html

时间: 2024-07-31 22:37:16

微信小程序动画之弹出菜单的相关文章

微信小程序开发视频教程新鲜出炉

微信小程序开发公测了,可是对于新手来说,不同的框架不同的开发机制,如何快速适应呢?微信小程序开发视频教程新鲜出炉了,从零开始一步一步搭建微信小程序,每个章节都会涉及到不同的知识点,等教程学习完你不但掌握了小程序开发全部知识,同时还拥有一个完整作品的开发经验! 有需要的朋友关注一下ytkah的微信,留言索取微信小程序开发视频教程!

微信小程序---动画

1.学习大纲: 2. //index.js //获取应用实例 var app = getApp() Page({ data: { motto: 'Hello World', userInfo: {}, animationData: [] }, //事件处理函数 bindViewTap: function() { console.log("点击了了...") // 点击头像开始动画 var animation = wx.createAnimation({ duration: 1000,

运用安卓CreateOptionsMenu和onCreateContextMenu菜单,模拟微信聊天界面长按弹出菜单选项。

1 package com.lixu.menu2; 2 3 import java.util.ArrayList; 4 5 import android.app.Activity; 6 import android.os.Bundle; 7 import android.view.ContextMenu; 8 import android.view.Menu; 9 import android.view.MenuItem; 10 import android.view.View; 11 impo

小程序 input 键盘弹出时样式遮盖问题

设置cursor-spacing,具体可参考官方文档,代码如下: <input type='text' bindinput="bindKeyInput"  placeholder='说点什么吧-' class='speakBM' value="{{speakValue}}" cursor-spacing='10'></input> 原文地址:https://www.cnblogs.com/keleyz/p/9680693.html

微信小程序爬坑日记

新公司上手小程序.30天,从入门到现在,还没放弃... 虽然小程序发布出来快一年了,爬坑的兄弟们大多把坑都踩平了.而我一直停留在"Hello World"的学习阶段.一来没项目,只有项目才是实践学习的根本:二来刚出来,总是有很多坑.爬坑总是痛并快乐着. 再多的借口,产品项目需求拍在桌前,都得缴械投降.不要怂撸起袖子,就是干. 初识小程序 微信推出小程序,想要实现即开即用,用完即走的用户体验.免去APP下载安装繁琐的流程.听起来像谷歌推出的PWA,不过PWA普及到国内还有段时间.而小程序

在微信小程序里自动获得当前手机所在的经纬度并转换成地址

效果:我在手机上打开微信小程序,自动显示出我当前所在的地理位置: 具体步骤: 1. 使用微信jssdk提供的getLocation API拿到经纬度: 2. 调用高德地图的api使用经纬度去换取地址的文字描述. wx.ready(() => { wx.getLocation({ type: "gcj02", success: function(res) { var location = "&location=" + res.longitude + &q

第一个微信小程序(实现点击一个按钮弹出toast)

今天根据网上的教程搭建了微信小程序的环境,然后看文档做了一个简单的小应用. 项目的目录是这个样子的: app.js.app.json.app.wxss是全局文件,必不可少的文件.定义在app.wxss中的样式为全局样式,作用于每一个页面.在page的wxss文件中定义的样式为局部样式,只作用在对应的页面,并会覆盖app.wxss中相同的选择器. app.js文件代码: App({ onLaunch: function () { console.log('小程序已启动') }, onShow: f

从一个程序员的角度看——微信小应用(第二弹 见解)

最近公司的小程序刚通过了代码审核(待发布状态),从最初对它的学习 到开发 到小程序待发布 再到28日微信公开课,也算一步步的了解了微信小程序吧. 28日微信pro公开课张小龙针对小程序进行了一些答疑,之后行业的同僚都很关注,似乎大家还是有很多疑惑.之前初学后写过博客 从一个程序员的角度看--微信小应用(第一弹 初学),今天决定再写一篇小程序的小文,所以此篇谈谈我对小程序的理解吧. 说说张小龙回答的8个问题 1.小程序的入口在哪里?张小龙给出的答案是:小程序在微信没有入口. 2.小程序会不会有类似

仿微信右上角弹出菜单

使用PopupWindow实现仿微信右上角弹出菜单. 效果图如下: popupWindow代码如下: import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.stcyclub.e_community.R; import android.app.Activity; import android.content.Context; impo