微信小程序自定义对话框弹出和隐藏动画


Posted in Javascript onJuly 19, 2018

本文实例为大家分享了微信小程序自定义对话框弹出和隐藏动画的具体代码,供大家参考,具体内容如下

index.js

//index.js
var app = getApp();
 
let animationShowHeight = 300;
 
Page({
 data:{
 animationData:"",
 showModalStatus:false,
 imageHeight:0,
 imageWidth:0
 },
 imageLoad: function (e) { 
 this.setData({imageHeight:e.detail.height,imageWidth:e.detail.width}); 
 },
 showModal: function () {
 // 显示遮罩层
 var animation = wx.createAnimation({
  duration: 200,
  timingFunction: "linear",
  delay: 0
 })
 this.animation = animation
 animation.translateY(animationShowHeight).step()
 this.setData({
  animationData: animation.export(),
  showModalStatus: true
 })
 setTimeout(function () {
  animation.translateY(0).step()
  this.setData({
  animationData: animation.export()
  })
 }.bind(this), 200)
 },
 hideModal: function () {
 // 隐藏遮罩层
 var animation = wx.createAnimation({
  duration: 200,
  timingFunction: "linear",
  delay: 0
 })
 this.animation = animation;
 animation.translateY(animationShowHeight).step()
 this.setData({
  animationData: animation.export(),
 })
 setTimeout(function () {
 animation.translateY(0).step()
 this.setData({
  animationData: animation.export(),
  showModalStatus: false
 })
 }.bind(this), 200)
 },
 onShow:function(){
  let that = this;
  wx.getSystemInfo({
  success: function(res) {
  animationShowHeight = res.windowHeight;
  }
 })
 },
 
})

index.wxml

<!--index.wxml-->
<view class="container-column">
 
 <view animation="{{animationData}}" class="container-column buydes-dialog-container" wx:if="{{showModalStatus}}">
 <view class="buydes-dialog-container-top" bindtap="hideModal"></view>
 <view class="container-column buydes-dialog-container-bottom">
  <block wx:for="{{['操作1','操作2','操作3','取消']}}" wx:for-index="index" wx:key="key" wx:for-item="item">
  <view bindtap="hideModal" class="buydes-dialog-container-bottom-item" >{{item}}</view>
  </block>
 </view>
 </view>
 
 <image bindtap="showModal" bindload="imageLoad" style="width:{{imageWidth}}px;;height:{{imageHeight}}px;" src="../pro1.jpg"/>
 
</view>

index.wxss

.buydes-dialog-container{
 width: 100%;
 height: 100%;
 justify-content: space-between;
 background-color:rgba(15, 15, 26, 0.7);
 position: fixed;
 z-index: 999;
}
 
.buydes-dialog-container-top{
 flex-grow: 1;
}
 
.buydes-dialog-container-bottom{
 display: flex;
 flex-grow: 0;
}
 
.buydes-dialog-container-bottom-item{
 padding:24rpx;
 display: flex;
 justify-content: center;
 border-bottom: 1rpx solid #eeeeee;
}

效果图:

微信小程序自定义对话框弹出和隐藏动画

下面是实际开发中的效果图,没有源码,但是原理和上面的是一样的,通过上面的DEMO学习加上平常的CSS基础,完全可以做出下面的效果

微信小程序自定义对话框弹出和隐藏动画

源码下载:微信小程序自定义对话框弹出和隐藏动画

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

Javascript 相关文章推荐
基于jquery的气泡提示效果
May 31 Javascript
JAVASCRIPT模式窗口中下载文件无法接收iframe的流
Oct 11 Javascript
js清空表单数据的两种方式(遍历+reset)
Jul 18 Javascript
node.js中的fs.unlink方法使用说明
Dec 15 Javascript
简单谈谈javascript代码复用模式
Jan 28 Javascript
jQuery实现首页顶部可伸缩广告特效代码
Apr 15 Javascript
javascript鼠标滑动评分控件完整实例
May 13 Javascript
HTML5之WebSocket入门3 -通信模型socket.io
Aug 21 Javascript
jQuery1.9.1源码分析系列(十六)ajax之ajax框架
Dec 04 Javascript
JQuery中attr属性和jQuery.data()学习笔记【必看】
May 18 Javascript
浅谈angular2路由预加载策略
Oct 04 Javascript
express默认日志组件morgan的方法
Apr 05 Javascript
浅谈Vue初学之props的驼峰命名
Jul 19 #Javascript
解决vue-cli3 使用子目录部署问题
Jul 19 #Javascript
详解vue2.0+axios+mock+axios-mock+adapter实现登陆
Jul 19 #Javascript
微信小程序实现分享到朋友圈功能
Jul 19 #Javascript
微信小程序实现自定义加载图标功能
Jul 19 #Javascript
Angular5集成eventbus的示例代码
Jul 19 #Javascript
微信小程序实现弹出菜单
Jul 19 #Javascript
You might like
mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数
2010/03/21 PHP
THINKPHP支持YAML配置文件的设置方法
2015/03/17 PHP
ThinkPHP框架搭建及常见问题(XAMPP安装失败、Apache/MySQL启动失败)
2016/04/15 PHP
数据结构之利用PHP实现二分搜索树
2020/10/25 PHP
PHP常用字符串输出方法分析(echo,print,printf及sprintf)
2021/03/09 PHP
JQuery 学习笔记 选择器之五
2009/07/23 Javascript
JavaScript用JQuery呼叫Server端方法示例代码
2014/09/03 Javascript
jQuery+PHP+MySQL二级联动下拉菜单实例讲解
2015/10/27 Javascript
详解Wondows下Node.js使用MongoDB的环境配置
2016/03/01 Javascript
jQuery实现的简单拖拽功能示例
2016/09/13 Javascript
同步异步动态引入js文件的几种方法总结
2016/09/23 Javascript
详解ECharts使用心得总结
2016/12/06 Javascript
Vue自定义指令实现checkbox全选功能的方法
2018/02/28 Javascript
详解swipe使用及竖屏页面滚动方法
2018/06/28 Javascript
vue 2.1.3 实时显示当前时间,每秒更新的方法
2018/09/16 Javascript
微信小程序与公众号卡券/会员打通的问题
2019/07/25 Javascript
extjs图表绘制之条形图实现方法分析
2020/03/06 Javascript
vue项目打包后请求地址错误/打包后跨域操作
2020/11/04 Javascript
Python Tkinter GUI编程入门介绍
2015/03/10 Python
Python下线程之间的共享和释放示例
2015/05/04 Python
在CentOS上配置Nginx+Gunicorn+Python+Flask环境的教程
2016/06/07 Python
python Crypto模块的安装与使用方法
2017/12/21 Python
解决Django的request.POST获取不到内容的问题
2018/05/28 Python
在Python运行时动态查看进程内部信息的方法
2019/02/22 Python
Python-for循环的内部机制
2020/06/12 Python
python和c语言哪个更适合初学者
2020/06/22 Python
CSS3制作炫酷带方向感应的鼠标滑过图片3D动画
2016/03/16 HTML / CSS
药品促销活动方案
2014/02/14 职场文书
产品包装策划方案
2014/05/18 职场文书
民主生活会剖析材料
2014/09/30 职场文书
2016年国陪研修感言
2015/11/18 职场文书
班级班风口号大全
2015/12/25 职场文书
浅谈:电影《孔子》观后感(范文)
2019/10/14 职场文书
mysql 8.0.24版本安装配置方法图文教程
2021/05/12 MySQL
springcloud之Feign超时问题的解决
2021/06/24 Java/Android
java泛型通配符详解
2021/07/25 Java/Android