1. <view class="modals modals-bottom-dialog" hidden="{{hideModal}}">
    2. <view class="modals-cancel" bindtap="hideModal"></view>
    3. <view class="bottom-dialog-body bottom-pos" animation="{{animationData}}"></view>
    4. </view>
    5. <button bindtap="showModal">点我</button>
    1. /*模态框*/
    2. .modals{position:fixed; z-index: 999; top:0; left: 0; right:0; bottom: 0;}
    3. .modals-cancel{position:absolute; z-index:1000; top:0; left: 0; right:0; bottom: 0; background-color: rgba(0,0,0,.5);}
    4. .bottom-dialog-body{position:absolute; z-index:10001; bottom:0; left:0; right:0; padding:30rpx; height:300rpx; background-color: #fff;}
    5. /*动画前初始位置*/
    6. .bottom-pos{-webkit-transform:translateY(100%);transform:translateY(100%);}
    1. Page({
    2. data:{
    3. hideModal:true, //模态框的状态 true-隐藏 false-显示
    4. animationData:{},//
    5. },
    6. // 显示遮罩层
    7. showModal: function () {
    8. var that=this;
    9. that.setData({
    10. hideModal:false
    11. })
    12. var animation = wx.createAnimation({
    13. duration: 600,//动画的持续时间 默认400ms 数值越大,动画越慢 数值越小,动画越快
    14. timingFunction: 'ease',//动画的效果 默认值是linear
    15. })
    16. this.animation = animation
    17. setTimeout(function(){
    18. that.fadeIn();//调用显示动画
    19. },200)
    20. },
    21. // 隐藏遮罩层
    22. hideModal: function () {
    23. var that=this;
    24. var animation = wx.createAnimation({
    25. duration: 800,//动画的持续时间 默认400ms 数值越大,动画越慢 数值越小,动画越快
    26. timingFunction: 'ease',//动画的效果 默认值是linear
    27. })
    28. this.animation = animation
    29. that.fadeDown();//调用隐藏动画
    30. setTimeout(function(){
    31. that.setData({
    32. hideModal:true
    33. })
    34. },720)//先执行下滑动画,再隐藏模块
    35. },
    36. //动画集
    37. fadeIn:function(){
    38. this.animation.translateY(0).step()
    39. this.setData({
    40. animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性
    41. })
    42. },
    43. fadeDown:function(){
    44. this.animation.translateY(300).step()
    45. this.setData({
    46. animationData: this.animation.export(),
    47. })
    48. },
    49. })