微信小程序实现弹出菜单


Posted in Javascript onJuly 19, 2018

本文实例为大家分享了微信小程序实现弹出菜单的具体代码,供大家参考,具体内容如下

菜单

微信小程序实现弹出菜单

代码:

1.index.js

//index.js
//获取应用实例
var app = getApp()
Page({
 data: {
 isPopping: false,//是否已经弹出
 animationPlus: {},//旋转动画
 animationcollect: {},//item位移,透明度
 animationTranspond: {},//item位移,透明度
 animationInput: {},//item位移,透明度
 //我的博客:http://blog.csdn.net/qq_31383345
 //CSDN微信小程序开发专栏:http://blog.csdn.net/column/details/13721.html
 },
 onLoad: function () {

 },
 //点击弹出
 plus: function () {
 if (this.data.isPopping) {
  //缩回动画
  popp.call(this);
  this.setData({
  isPopping: false
  })
 } else {
  //弹出动画
  takeback.call(this);
  this.setData({
  isPopping: true
  })
 }
 },
 input: function () {
 console.log("input")
 },
 transpond: function () {
 console.log("transpond")
 },
 collect: function () {
 console.log("collect")
 }
})



//弹出动画
function popp() {
 //plus顺时针旋转
 var animationPlus = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationcollect = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationTranspond = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationInput = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 animationPlus.rotateZ(180).step();
 animationcollect.translate(-100, -100).rotateZ(180).opacity(1).step();
 animationTranspond.translate(-140, 0).rotateZ(180).opacity(1).step();
 animationInput.translate(-100, 100).rotateZ(180).opacity(1).step();
 this.setData({
 animationPlus: animationPlus.export(),
 animationcollect: animationcollect.export(),
 animationTranspond: animationTranspond.export(),
 animationInput: animationInput.export(),
 })
}
//收回动画
function takeback() {
 //plus逆时针旋转
 var animationPlus = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationcollect = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationTranspond = wx.createAnimation({
 duration: 500,
 timingFunction: 'ease-out'
 })
 var animationInput = wx.createAnimation({
 duration: 500,
 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();
 this.setData({
 animationPlus: animationPlus.export(),
 animationcollect: animationcollect.export(),
 animationTranspond: animationTranspond.export(),
 animationInput: animationInput.export(),
 })
}

2.index.wxml

<!--index.wxml-->
<image src="../../images/collect.png" animation="{{animationcollect}}" class="image-style" bindtap="collect"></image>
<image src="../../images/transpond.png" animation="{{animationTranspond}}" class="image-style" bindtap="transpond"></image>
<image src="../../images/input.png" animation="{{animationInput}}" class="image-style" bindtap="input"></image>
<image src="../../images/plus.png" animation="{{animationPlus}}" class="image-plus-style" bindtap="plus"></image>

3.index.wxss

/**index.wxss**/

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

.image-plus-style {
 height: 150rpx;
 width: 150rpx;
 position: absolute;
 bottom: 250rpx;
 right: 100rpx;
 z-index: 100;
}

demo代码下载

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
JavaScript代码复用模式详解
Nov 07 Javascript
js获取图片宽高的方法
Nov 25 Javascript
JavaScript html5 canvas绘制时钟效果
Mar 01 Javascript
JavaScript程序中实现继承特性的方式总结
Jun 24 Javascript
Node.js中文件操作模块File System的详细介绍
Jan 05 Javascript
浅谈jQuery中事情的动态绑定
Feb 12 Javascript
vue的.vue文件是怎么run起来的(vue-loader)
Dec 10 Javascript
微信小程序MUI导航栏透明渐变功能示例(通过改变rgba的a值实现)
Jan 24 Javascript
小程序测试后台服务的方法(ngrok)
Mar 08 Javascript
Vue中keep-alive组件作用详解
Feb 04 Javascript
解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题
Jul 27 Javascript
js实现三角形粒子运动
Sep 22 Javascript
微信小程序实现之手势锁功能实例代码
Jul 19 #Javascript
React组件重构之嵌套+继承及高阶组件详解
Jul 19 #Javascript
微信小程序实现折叠展开效果
Jul 19 #Javascript
详解Angularjs 自定义指令中的数据绑定
Jul 19 #Javascript
微信小程序实现天气预报功能
Jul 18 #Javascript
vue代理和跨域问题的解决
Jul 18 #Javascript
小程序自定义组件实现城市选择功能
Jul 18 #Javascript
You might like
Protoss魔法科技
2020/03/14 星际争霸
php递归法读取目录及文件的方法
2015/01/30 PHP
PHP输入输出流学习笔记
2015/05/12 PHP
Yii清理缓存的方法
2016/01/06 PHP
php bootstrap实现简单登录
2016/03/08 PHP
Yii2中SqlDataProvider用法示例
2016/09/22 PHP
如何用javascript判断录入的日期是否合法
2007/01/08 Javascript
JavaScript 学习笔记(九)call和apply方法
2010/01/11 Javascript
Javascript模块化编程(一)模块的写法最佳实践
2013/01/17 Javascript
javascript使用location.search的示例
2013/11/05 Javascript
jquery插件jquery.beforeafter.js实现左右拖拽分隔条对比图片的方法
2015/08/07 Javascript
jQuery实现可展开合拢的手风琴面板菜单
2015/09/15 Javascript
Javascript的动态增加类的实现方法
2016/10/20 Javascript
javascript将url解析为json格式的两种方法
2017/08/18 Javascript
vue-cli如何引入bootstrap工具的方法
2017/10/19 Javascript
layui 实现加载动画以及非真实加载进度的方法
2019/09/23 Javascript
VUE使用 wx-open-launch-app 组件开发微信打开APP功能
2020/08/11 Javascript
DataFrame:通过SparkSql将scala类转为DataFrame的方法
2019/01/29 Python
使用python实现抓取腾讯视频所有电影的爬虫
2019/04/15 Python
python自动化工具之pywinauto实例详解
2019/08/26 Python
python GUI库图形界面开发之PyQt5菜单栏控件QMenuBar的详细使用方法与实例
2020/02/28 Python
Python接口测试get请求过程详解
2020/02/28 Python
Python Pygame实现俄罗斯方块
2021/02/19 Python
美国顶级奢侈茶:Mighty Leaf Tea(美泰茶)
2016/11/26 全球购物
SEPHORA丝芙兰德国官方购物网站:化妆品、护肤品和香水
2020/01/21 全球购物
北京-环亚运商测试题.net程序员初步测试题
2013/05/28 面试题
Python面试题集
2012/03/08 面试题
实习教师自我鉴定
2013/12/12 职场文书
爱心倡议书范文
2014/05/12 职场文书
2019学校运动会开幕词
2019/05/13 职场文书
php 防护xss,PHP的防御XSS注入的终极解决方案
2021/04/01 PHP
详解MongoDB的条件查询和排序
2021/06/23 MongoDB
Python爬虫基础之初次使用scrapy爬虫实例
2021/06/26 Python
sql时间段切分实现每隔x分钟出一份高速门架车流量
2022/02/28 SQL Server
MongoDB修改oplog大小的四种方法
2022/04/11 MongoDB
python小型的音频操作库mp3Play
2022/04/24 Python