找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

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

作者:模板之家 2017-12-1 15:20 7323人关注

index.js view plain copy //index.js var app=getApp(); letanimationShowHeight=300; Page({ data:{ animationData: , showModalStatus: false , imageHeight:0, imageWidth:0 }, imageLoad: function (e){ this ...

index.js

 

[javascript] view plain copy
 
 
  1. //index.js  
  2. var app = getApp();  
  3.   
  4. let animationShowHeight = 300;  
  5.   
  6. Page({  
  7.   data:{  
  8.         animationData:"",  
  9.         showModalStatus:false,  
  10.         imageHeight:0,  
  11.         imageWidth:0  
  12.   },  
  13.   imageLoad: function (e) {    
  14.         this.setData({imageHeight:e.detail.height,imageWidth:e.detail.width});    
  15.   },  
  16.   showModal: function () {  
  17.         // 显示遮罩层  
  18.         var animation = wx.createAnimation({  
  19.             duration: 200,  
  20.             timingFunction: "linear",  
  21.             delay: 0  
  22.         })  
  23.         this.animation = animation  
  24.         animation.translateY(animationShowHeight).step()  
  25.         this.setData({  
  26.             animationData: animation.export(),  
  27.             showModalStatus: true  
  28.         })  
  29.         setTimeout(function () {  
  30.             animation.translateY(0).step()  
  31.             this.setData({  
  32.                 animationData: animation.export()  
  33.             })  
  34.         }.bind(this), 200)  
  35.     },  
  36.     hideModal: function () {  
  37.         // 隐藏遮罩层  
  38.         var animation = wx.createAnimation({  
  39.             duration: 200,  
  40.             timingFunction: "linear",  
  41.             delay: 0  
  42.         })  
  43.         this.animation = animation;  
  44.         animation.translateY(animationShowHeight).step()  
  45.         this.setData({  
  46.             animationData: animation.export(),  
  47.         })  
  48.         setTimeout(function () {  
  49.         animation.translateY(0).step()  
  50.         this.setData({  
  51.             animationData: animation.export(),  
  52.             showModalStatus: false  
  53.         })  
  54.         }.bind(this), 200)  
  55.     },  
  56.      onShow:function(){  
  57.          let that = this;  
  58.          wx.getSystemInfo({  
  59.             success: function(res) {  
  60.                 animationShowHeight = res.windowHeight;  
  61.             }  
  62.         })  
  63.      },  
  64.   
  65. })  

 

 

index.wxml
[java] view plain copy
 
 
  1. <!--index.wxml-->  
  2. <view class="container-column">  
  3.      
  4.     <view animation="{{animationData}}" class="container-column buydes-dialog-container" wx:if="{{showModalStatus}}">  
  5.         <view class="buydes-dialog-container-top" bindtap="hideModal"></view>  
  6.         <view class="container-column buydes-dialog-container-bottom">  
  7.           <block wx:for="{{['操作1','操作2','操作3','取消']}}" wx:for-index="index" wx:key="key" wx:for-item="item">  
  8.               <view bindtap="hideModal"  邀请

路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)