微信小程序自定义对话框弹出和隐藏动画

本文实例为大家分享了微信小程序自定义对话框弹出和隐藏动画的具体代码,供大家参考,具体内容如下

index.js

//index.js
var app = getApp();

let animationShowHeight = 300;

Page({
 data:{
 animationData:"",
 showModalStatus:false,
 imageHeight:0,
 imageWidth:0
 },
 imageLoad: function (e) {
 this.setData({imageHeight:e.detail.height,imageWidth:e.detail.width});
 },
 showModal: function () {
 // 显示遮罩层
 var animation = wx.createAnimation({
  duration: 200,
  timingFunction: "linear",
  delay: 0
 })
 this.animation = animation
 animation.translateY(animationShowHeight).step()
 this.setData({
  animationData: animation.export(),
  showModalStatus: true
 })
 setTimeout(function () {
  animation.translateY(0).step()
  this.setData({
  animationData: animation.export()
  })
 }.bind(this), 200)
 },
 hideModal: function () {
 // 隐藏遮罩层
 var animation = wx.createAnimation({
  duration: 200,
  timingFunction: "linear",
  delay: 0
 })
 this.animation = animation;
 animation.translateY(animationShowHeight).step()
 this.setData({
  animationData: animation.export(),
 })
 setTimeout(function () {
 animation.translateY(0).step()
 this.setData({
  animationData: animation.export(),
  showModalStatus: false
 })
 }.bind(this), 200)
 },
 onShow:function(){
  let that = this;
  wx.getSystemInfo({
  success: function(res) {
  animationShowHeight = res.windowHeight;
  }
 })
 },

})

index.wxml

<!--index.wxml-->
<view class="container-column">

 <view animation="{{animationData}}" class="container-column buydes-dialog-container" wx:if="{{showModalStatus}}">
 <view class="buydes-dialog-container-top" bindtap="hideModal"></view>
 <view class="container-column buydes-dialog-container-bottom">
  <block wx:for="{{['操作1','操作2','操作3','取消']}}" wx:for-index="index" wx:key="key" wx:for-item="item">
  <view bindtap="hideModal" class="buydes-dialog-container-bottom-item" >{{item}}</view>
  </block>
 </view>
 </view>

 <image bindtap="showModal" bindload="imageLoad" style="width:{{imageWidth}}px;;height:{{imageHeight}}px;" src="../pro1.jpg"/>

</view>

index.wxss

.buydes-dialog-container{
 width: 100%;
 height: 100%;
 justify-content: space-between;
 background-color:rgba(15, 15, 26, 0.7);
 position: fixed;
 z-index: 999;
}

.buydes-dialog-container-top{
 flex-grow: 1;
}

.buydes-dialog-container-bottom{
 display: flex;
 flex-grow: 0;
}

.buydes-dialog-container-bottom-item{
 padding:24rpx;
 display: flex;
 justify-content: center;
 border-bottom: 1rpx solid #eeeeee;
}

效果图:

下面是实际开发中的效果图,没有源码,但是原理和上面的是一样的,通过上面的DEMO学习加上平常的CSS基础,完全可以做出下面的效果

源码下载:微信小程序自定义对话框弹出和隐藏动画

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • 微信小程序实现action-sheet弹出底部菜单功能【附源码下载】

    本文实例讲述了微信小程序实现action-sheet弹出底部菜单功能.分享给大家供大家参考,具体如下: 1.效果展示 2.关键代码 ① index.wxml <button type="default" bindtap="actionSheetTap">弹出action sheet</button> <action-sheet hidden="{{actionSheetHidden}}" bindchange=&qu

  • 微信小程序实现的点击按钮 弹出底部上拉菜单功能示例

    本文实例讲述了微信小程序实现的点击按钮 弹出底部上拉菜单功能.分享给大家供大家参考,具体如下: index.wxml <button type="default" bindtap="actionSheetTap">弹出action sheet</button> <action-sheet hidden="{{actionSheetHidden}}" bindchange="actionSheetbindch

  • 微信小程序实现弹出菜单功能

    需求 点击标签栏按钮,向下弹出菜单,再次点击,收回菜单 要解决的问题 标签栏三栏样式,标签栏固定不动: 点击标签栏弹出菜单,并且出现透明遮罩: 遮罩优先级在弹出框之下: 弹出框内标签的设置: 滚动栏滚动条的隐藏 如何解决? 弹性布局,横向,三者平分整栏; 状态监听点击事件,数据控制hide或者show,通过rgba设置透明度 弹出框设置z-index: 弹性布局flex 横向排列 超出后wrap 然后space-around控制间距 ::-webkit-scrollbar { width: 0;

  • 微信小程序自定义底部弹出框

    本文实例为大家分享了微信小程序底部弹出框展示的具体代码,供大家参考,具体内容如下 效果图: html <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view> <view animation="{{animationData}}" class="commodity_attr

  • 微信小程序使用modal组件弹出对话框功能示例

    本文实例讲述了微信小程序使用modal组件弹出对话框功能.分享给大家供大家参考,具体如下: 1.效果展示 2.关键代码 ①.index.wxml <view>提示:{{tip}}</view> <button type="default" bindtap="showModal">点击我弹出modal对话框</button> <view> <modal title="modal对话框"

  • JS中微信小程序自定义底部弹出框

    实现微信小程序底部弹出框效果,代码分为html,css和js两部分,具体代码详情大家参考下本文. html <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view> <view animation="{{animationData}}" class="commodity_a

  • 微信小程序商品详情页的底部弹出框效果

    电商项目中商品详情页,加入购物车或者下单时可以选择商品属性的弹出框,通过设置view的平移动画,达到从底部弹出的样式 1.js代码(一般情况下只调用显示对话框的函数,当点击对话框外部的时候,对话框可以消失) //显示对话框 showModal: function () { // 显示遮罩层 var animation = wx.createAnimation({ duration: 200, timingFunction: "linear", delay: 0 }) this.anim

  • 微信小程序实现弹出层效果

    本文实例为大家分享了微信小程序实现弹出层效果的具体代码,供大家参考,具体内容如下 先看下效果图吧 其实这个效果实现起来很简单,就是通过三目运算符来控制遮罩层的显示和隐藏 贴代码了: 规则按钮: <text class='rule' bindtap='showRule'>规则</text> 遮罩层:我这个数据是从后台拿来动态渲染到页面的 <!-- 规则提示 --> <view class="ruleZhezhao {{isRuleTrue?'isRuleS

  • 微信小程序实现消息框弹出动画

    微信小程序动画之消息框弹出,供大家参考,具体内容如下 上图 js: Page({ data: { showModalStatus: false }, powerDrawer: function(e) { var currentStatu = e.currentTarget.dataset.statu; this.util(currentStatu) }, util: function(currentStatu) { /* 动画部分 */ // 第1步:创建动画实例 var animation =

  • 使用微信小程序开发弹出框应用实例详解

    view class="container" class="zn-uploadimg"> <button type="primary"bindtap="showok">消息提示框</button> <button type="primary"bindtap="modalcnt">模态弹窗</button> <button typ

随机推荐