前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >小程序底部动画弹框

小程序底部动画弹框

作者头像
王小婷
发布2018-12-27 15:29:58
1.9K0
发布2018-12-27 15:29:58
举报
文章被收录于专栏:编程微刊编程微刊

接上一篇的举一反三:微信小程序商品筛选,侧方弹出动画选择页面:https://cloud.tencent.com/developer/article/1379064;这个小程序底部动画弹框也是项目之中常见的功能之一,效果如下图所示。

wxml

代码语言:javascript
复制
<view class="modals modals-bottom-dialog" hidden="{{hideModal}}">
  <view class="modals-cancel" bindtap="hideModal"></view>
  <view class="bottom-dialog-body bottom-pos" animation="{{animationData}}">
    <button class="yuyue" bindtap="subscribe">立即预约</button>
  </view>
</view>
<button bindtap="showModal" class="yuyue-to">立即预约</button>

wxss

代码语言:javascript
复制
/**index.wxss**/

/*模态框*/
.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;
  height: 680rpx;
  background-color: #fff;
}

/*动画前初始位置*/

.bottom-pos {
  -webkit-transform: translateY(100%);
  transform: translateY(100%);
}

.yuyue {
  width: 100%;
  height: 100rpx;
  z-index: 9999;
  position: fixed;
  bottom: 0;
  border-radius: 0;
  border: 0;
  color: #fff;
  font-size: 40rpx;
  line-height: 100rpx;
  background-color: #069ff8;
}

.yuyue-to {
  width: 100%;
  height: 100rpx;
  position: fixed;
  bottom: 0;
  border-radius: 0;
  border: 0;
  color: #fff;
  font-size: 40rpx;
  line-height: 100rpx;
 background-color: #069ff8;
}

js

代码语言:javascript
复制
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    hideModal: true, //模态框的状态  true-隐藏  false-显示
  },
  // 显示遮罩层 
  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(),
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {

  },
})

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.12.20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档