底部弹出动画

<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>
Page({
  data: {
    hideModal: true, //模态框的状态  true-隐藏  false-显示
    animationData: {}, //
  },

  // 显示遮罩层
  showModal: function() {
    var that = this;
    that.setData({
      hideModal: false
    })
    var animation = wx.createAnimation({
      duration: 200, //动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快
      timingFunction: 'ease', //动画的效果 默认值是linear
    })
    this.animation = animation
    setTimeout(function() {
      that.fadeIn(); //调用显示动画
    }, 200)
  },

  // 隐藏遮罩层
  hideModal: function() {
    var that = this;
    var animation = wx.createAnimation({
      duration: 200, //动画的持续时间 默认400ms   数值越大,动画越慢   数值越小,动画越快
      timingFunction: 'ease', //动画的效果 默认值是linear
    })
    this.animation = animation
    that.fadeDown(); //调用隐藏动画   
    setTimeout(function() {
      that.setData({
        hideModal: true
      })
    }, 200) //先执行下滑动画,再隐藏模块

  },

  //动画集
  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(),
    })
  },
})
/*模态框*/

.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, 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%);
}

你可以使用 Vue 的过渡动画来实现底部弹出动画。以下是一种可能的实现方式: 1. 首先,在你的组件上添加一个 `v-if` 或 `v-show` 指令,用于控制弹出框的显示与隐藏。 2. 在你的组件上添加一个 `transition` 组件,指定过渡动画的名称和持续时间。例如: ``` <transition name="slide-up" mode="out-in" :duration="{ enter: 300, leave: 200 }"> <div v-if="showPopup" class="popup"> <!-- 弹出框内容 --> </div> </transition> ``` 这里的 `name` 属性指定了过渡动画的名称,`mode` 属性指定了过渡模式为 `out-in`,表示先执行离开动画再执行进入动画。`duration` 属性指定了进入和离开动画的持续时间。 3. 在你的 CSS 文件中定义过渡动画的样式。例如: ``` .slide-up-enter-active, .slide-up-leave-active { transition: transform 0.3s ease-out; } .slide-up-enter, .slide-up-leave-to { transform: translateY(100%); } ``` 这里的 `.slide-up-enter-active` 和 `.slide-up-leave-active` 类指定了进入和离开动画的过渡效果,这里使用了 `transform` 属性来实现弹出框从底部平移进入或平移离开的效果。`.slide-up-enter` 和 `.slide-up-leave-to` 类指定了进入和离开动画的初始和结束状态。 4. 最后,在你的组件中添加一个方法来控制弹出框的显示与隐藏。例如: ``` export default { data() { return { showPopup: false } }, methods: { togglePopup() { this.showPopup = !this.showPopup } } } ``` 你可以在需要的事件中调用该方法,例如点击按钮时触发。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值