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


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 SELECT单选模拟jQuery.select.js
Nov 12 Javascript
找出字符串中出现次数最多的字母和出现次数精简版
Nov 07 Javascript
IE的事件传递-event.cancelBubble示例介绍
Jan 12 Javascript
JS HTML5拖拽上传图片预览
Jul 18 Javascript
JavaScript Date 知识浅析
Jan 29 Javascript
Vue2 Vue-cli中使用Typescript的配置详解
Jul 24 Javascript
Angular.js前台传list数组由后台spring MVC接收数组示例代码
Jul 31 Javascript
微信小程序loading组件显示载入动画用法示例【附源码下载】
Dec 09 Javascript
详解ES6语法之可迭代协议和迭代器协议
Jan 13 Javascript
Vue-cropper 图片裁剪的基本原理及思路讲解
Apr 17 Javascript
修改vue+webpack run build的路径方法
Sep 01 Javascript
js实现点击展开隐藏效果(实例代码)
Sep 28 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
ThinkPHP的RBAC(基于角色权限控制)深入解析
2013/06/17 PHP
浅析php变量修饰符static的使用
2013/06/28 PHP
使用PHP获取当前url路径的函数以及服务器变量
2013/06/29 PHP
PHP实现将优酷土豆腾讯视频html地址转换成flash swf地址的方法
2017/08/04 PHP
PHP读取并输出XML文件数据的简单实现方法
2017/12/22 PHP
javascript之querySelector和querySelectorAll使用介绍
2011/12/20 Javascript
jquery对ajax的支持介绍
2013/12/10 Javascript
用js闭包的方法实现多点标注冒泡示例
2014/05/29 Javascript
非jQuery实现照片散落桌子上,单击放大的LightBox效果
2014/11/28 Javascript
ubuntu下安装nodejs以及升级的办法
2015/05/08 NodeJs
JavaScript原生xmlHttp与jquery的ajax方法json数据格式实例
2015/12/04 Javascript
jQuery实现三级菜单的代码
2016/05/09 Javascript
微信小程序 Tab页切换更新数据
2017/01/05 Javascript
jQuery实现菜单栏导航效果
2017/08/15 jQuery
使用mint-ui开发项目的一些心得(分享)
2017/09/07 Javascript
解决v-for中使用v-if或者v-bind:class失效的问题
2018/09/25 Javascript
webpack4 SplitChunks实现代码分隔详解
2019/05/23 Javascript
React组件对子组件children进行加强的方法
2019/06/23 Javascript
node.js express框架实现文件上传与下载功能实例详解
2019/10/15 Javascript
js判断浏览器的环境(pc端,移动端,还是微信浏览器)
2020/12/24 Javascript
微信小程序仿抖音视频之整屏上下切换功能的实现代码
2020/05/24 Javascript
[02:13] 完美世界DOTA2联赛PWL DAY5集锦
2020/11/03 DOTA
关于Python内存分配时的小秘密分享
2019/09/05 Python
Python Django框架防御CSRF攻击的方法分析
2019/10/18 Python
使用Keras训练好的.h5模型来测试一个实例
2020/07/06 Python
python中strip(),lstrip(),rstrip()函数的使用讲解
2020/11/17 Python
广州盈通面试题
2015/12/05 面试题
音乐学个人的自荐书范文
2013/11/26 职场文书
办公室助理岗位职责
2013/12/25 职场文书
医院工作检讨书范文
2014/02/10 职场文书
年会搞笑主持词
2014/03/27 职场文书
2014年科室工作总结范文
2014/12/19 职场文书
2016党员干部反腐倡廉心得体会
2016/01/13 职场文书
小学三年级语文教学反思
2016/03/03 职场文书
vue完美实现el-table列宽自适应
2021/05/08 Vue.js
一篇文章带你掌握SQLite3基本用法
2022/06/14 数据库