微信小程序实现弹出菜单


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 相关文章推荐
TFDN图片播放器 不错自动播放
Oct 03 Javascript
js 数组克隆方法 小结
Mar 20 Javascript
在JavaScript中获取请求的URL参数
Dec 22 Javascript
JavaScript高级程序设计(第3版)学习笔记2 js基础语法
Oct 11 Javascript
script不刷新页面的联动前后代码
Sep 18 Javascript
jQuery中andSelf()方法用法实例
Jan 08 Javascript
js窗口关闭提示信息(兼容IE和firefox)
Oct 23 Javascript
基于JavaScript怎么实现让歌词滚动播放
Nov 03 Javascript
jQuery siblings()用法实例详解
Apr 26 Javascript
React组件中的this的具体使用
Feb 28 Javascript
vue中父子组件注意事项,传值及slot应用技巧
May 09 Javascript
vue 自动化路由实现代码
Sep 03 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
令PHP初学者头疼十四条问题大总结
2008/11/12 PHP
Symfony2中被遗弃的getRequest()方法分析
2016/03/17 PHP
PHP中类的继承和用法实例分析
2016/05/24 PHP
PHP魔术方法之__call与__callStatic使用方法
2017/07/23 PHP
基于JQuery的数字改变的动画效果--可用来做计数器
2010/08/11 Javascript
jQuery插件分享之分页插件jqPagination
2014/06/06 Javascript
JQuery实现防止退格键返回的方法
2015/02/12 Javascript
JavaScript 里的类数组对象
2015/04/08 Javascript
JavaScript中的Math.LOG2E属性使用详解
2015/06/14 Javascript
JS实现的网页背景闪电闪烁效果代码
2015/10/17 Javascript
JavaScript中获取Radio被选中的值
2015/11/11 Javascript
javascript高级选择器querySelector和querySelectorAll全面解析
2016/04/07 Javascript
原生js实现百叶窗效果及原理介绍
2016/04/12 Javascript
javascript之Array 数组对象详解
2016/06/07 Javascript
js获取时间函数及扩展函数的方法
2016/10/30 Javascript
深入浅析Node.js单线程模型
2017/07/10 Javascript
jQuery实现拼图小游戏(实例讲解)
2017/07/24 jQuery
layui实现文件或图片上传记录
2018/08/28 Javascript
Angular使用cli生成自定义文件、组件的方法
2018/09/04 Javascript
详解vuex之store拆分即多模块状态管理(modules)篇
2018/11/13 Javascript
JS使用队列对数组排列,基数排序算法示例
2019/03/02 Javascript
js中addEventListener()与removeEventListener()用法案例分析
2020/03/02 Javascript
jquery实现简单每周轮换的日历
2020/09/10 jQuery
[56:38]DOTA2-DPC中国联赛正赛Aster vs Magma BO3 第一场 3月5日
2021/03/11 DOTA
总结Python编程中三条常用的技巧
2015/05/11 Python
Python利用pandas计算多个CSV文件数据值的实例
2018/04/19 Python
CSS3中的弹性布局em运用入门详解 1em等于多少像素
2021/02/08 HTML / CSS
越南电子产品购物网站:FPT Shop
2017/12/02 全球购物
英国最大的宠物商店:Pets at Home
2019/04/17 全球购物
介绍一下Linux中的链接
2016/05/28 面试题
什么是GWT的Entry Point
2013/08/16 面试题
2016自主招生校长推荐信范文
2015/03/23 职场文书
大专护理专业自荐信
2015/03/25 职场文书
导游词之西递宏村
2019/12/10 职场文书
Java版 单机五子棋
2022/05/04 Java/Android
Python 绘制多因子柱状图
2022/05/11 Python