博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序之自定义底部弹出框动画
阅读量:4704 次
发布时间:2019-06-10

本文共 1833 字,大约阅读时间需要 6 分钟。

 

最近做小程序时,会经常用到各种弹框。直接做显示和隐藏虽然也能达到效果,但是体验性太差,也比较简单粗暴。想要美美地玩,添加点动画还是非常有必要的。下面做一个底部上滑的弹框。

 

wxml

wxss

/*模态框*/.modals{
position:fixed; z-index: 999; top:0; left: 0; right:0; bottom: 0;}.modals-cancel{
position:absolute; z-index:1000; top:0; left: 0; right:0; bottom: 0; background-color: rgba(0,0,0,.5);}.bottom-dialog-body{
position:absolute; z-index:10001; bottom:0; left:0; right:0; padding:30rpx; height:300rpx; background-color: #fff;}/*动画前初始位置*/.bottom-pos{
-webkit-transform:translateY(100%);transform:translateY(100%);}

关键的部分来啦~~

js

Page({    data:{      hideModal:true, //模态框的状态  true-隐藏  false-显示      animationData:{},//    },  // 显示遮罩层    showModal: function () {    var that=this;    that.setData({      hideModal:false    })    var animation = wx.createAnimation({      duration: 600,//动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快      timingFunction: 'ease',//动画的效果 默认值是linear    })    this.animation = animation     setTimeout(function(){      that.fadeIn();//调用显示动画    },200)     },  // 隐藏遮罩层  hideModal: function () {    var that=this;     var animation = wx.createAnimation({      duration: 800,//动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快      timingFunction: 'ease',//动画的效果 默认值是linear    })    this.animation = animation    that.fadeDown();//调用隐藏动画       setTimeout(function(){      that.setData({        hideModal:true      })          },720)//先执行下滑动画,再隐藏模块      },  //动画集  fadeIn:function(){    this.animation.translateY(0).step()    this.setData({      animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性    })      },  fadeDown:function(){    this.animation.translateY(300).step()    this.setData({      animationData: this.animation.export(),      })  }, })

 

 

转 : https://www.jianshu.com/p/cea2d4dc24d1

 

转载于:https://www.cnblogs.com/fps2tao/p/11364740.html

你可能感兴趣的文章
在Linux自己Home下安装python
查看>>
SceneGrabber NET 视频批量自动截图软件使用技巧
查看>>
Codeforces985E. Pencils and Boxes (单调队列)
查看>>
python 打印进度条
查看>>
Art Pipeline for glTF
查看>>
Spring Boot配置
查看>>
芒果云 在线代码编辑器
查看>>
《从零开始学Swift》学习笔记(Day 16)——字典集合
查看>>
NOIP2012Day2 T1/T2题解
查看>>
hdu 2689
查看>>
C#和Unity总结Day01
查看>>
SQLAlchemy中解决数据库访问时出现的Incorrect string value: xxx at row 484
查看>>
5238-整数校验器-洛谷3月赛gg祭
查看>>
IOS 给按钮添加图片
查看>>
适合移动应用的日期时间拾取器
查看>>
【转载】很多女人都希望自己像薛之荔。但每个人心里都有一面是赵雯。
查看>>
JS设计模式(10)职责链模式(重要)
查看>>
三表查询、用到子查询,
查看>>
luogu P1726 上白泽慧音
查看>>
简单登录实例Login
查看>>