微信小程序之自定义底部弹出框动画,供大家参考,具体内容如下
最近做小程序时,会经常用到各种弹框。直接做显示和隐藏虽然也能达到效果,但是体验性太差,也比较简单粗暴。想要美美地玩,添加点动画还是非常有必要的。下面做一个底部上滑的弹框。
wxml
<view class="modals modals-bottom-dialog" hidden="{{hideModal}}"> <view class="modals-cancel" bindtap="hideModal"></view> <view class="bottom-dialog-body bottom-pos" animation="{{animationData}}"></view> </view> <button bindtap="showModal">点我</button>
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: 800rpx; 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(), }) }, })
为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“微信小程序自定义底部弹出框动画”评论...
更新动态
20240626
20240626
- 瑞鸣音乐《中国音乐地图之听见河南豫剧经典唱段》2020[WAV分轨]
- 【伊比萨沙发】VA-2024-IbizaSpring2024(LoungeCocktailsfromtheHeart)[FLAC]
- 群星《世界顶级汽车音响试音王》4K金碟16CD[WAV+CUE]
- 群星-音效环绕天碟《极致环绕人声天碟天品》7CD[WAV]
- 泰拉克SACD古典试音碟7SACD-ISO
- 群星《红歌宝典》20CD[WAV/分轨]
- 《101系列:好歌101首 细听年代精选》[WAV+CUE][3.6GB]
- 《101系列 6CD 国语经典101首歌曲 张学友 王菲代表作》[APE+CUE][2.8GB]
- 《101系列:国语经典101 VOL2 6CD 精选最经典101首》[WAV+CUE][2.3GB]
- 群星《十年网络红歌》15CD[WAV分轨]
- 宝丽金-环球10周年至50周年经典金曲15CD[低速原抓WAV+CUE]
- FIM唱片《十大男伶》[低速原抓WAV+CUE]
- 《101系列:情歌101 6CD》[WAV+CUE][3.1GB]
- 庄心妍《降调版合集》[320K/MP3][52.96MB]
- 庄心妍《降调版合集》[FLAC/分轨][118.78MB]