微信小程序之自定义模态弹窗(带动画)实例

摘要:
用户定义的带有动画的弹出框,以获取弹出框的内容,并自定义事件获取II。程序实现的具体步骤1.弹出框索引Wxml代码˂!

一、前期准备工作

软件环境:微信开发者工具
官方下载地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

1、基本需求。
  • 实现用户自定义弹框
  • 带动画(动画可做参靠,个人要是觉得不好看可以自定义动画)
  • 获取弹出框的内容,自定义事件获取

二、程序实现具体步骤

1.弹框index.wxml代码
<!--button-->
<view class="btn" bindtap="powerDrawer" data-statu="open">来点我呀</view>
 
<!--mask-->
<view class="drawer_screen" bindtap="powerDrawer" data-statu="close" wx:if="{{showModalStatus}}"></view>
<!--content-->
<!--使用animation属性指定需要执行的动画-->
<view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">
 
  <!--drawer content-->
  <view class="drawer_title">弹窗标题</view>
  <view class="drawer_content">
    <view class="top grid">
      <label class="title col-0">标题</label>
      <input class="input_base input_h30 col-1" name="rName" value="可自行定义内容"></input>
    </view>
    <view class="top grid">
      <label class="title col-0">标题</label>
      <input class="input_base input_h30 col-1" name="mobile" value="110"></input>
    </view>
    <view class="top grid">
      <label class="title col-0">标题</label>
      <input class="input_base input_h30 col-1" name="phone" value="拒绝伸手党"></input>
    </view>
    <view class="top grid">
      <label class="title col-0">标题</label>
      <input class="input_base input_h30 col-1" name="Email" value="仅供学习使用"></input>
    </view>
    <view class="top bottom grid">
      <label class="title col-0">备注</label>
      <input class="input_base input_h30 col-1" name="bz"></input>
    </view>
  </view>
  <view class="btn_ok" bindtap="powerDrawer" data-statu="close">确定</view>
</view>
2.弹框index.wxss代码
/*button*/
.btn {
   80%;
  padding: 20rpx 0;
  border-radius: 10rpx;
  text-align: center;
  margin: 40rpx 10%;
  background: #000;
  color: #fff;
}
 
/*mask*/
.drawer_screen {
   100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  background: #000;
  opacity: 0.5;
  overflow: hidden;
}
 
/*content*/
.drawer_box {
   650rpx;
  overflow: hidden;
  position: fixed;
  top: 50%;
  left: 0;
  z-index: 1001;
  background: #FAFAFA;
  margin: -150px 50rpx 0 50rpx;
  border-radius: 3px;
}
 
.drawer_title{
  padding:15px;
  font: 20px "microsoft yahei";
  text-align: center;
}
.drawer_content {
  height: 210px;
  overflow-y: scroll; /*超出父盒子高度可滚动*/
}
 
.btn_ok{
  padding: 10px;
  font: 20px "microsoft yahei";
  text-align: center;
  border-top: 1px solid #E8E8EA;
  color: #3CC51F;
}
 
.top{
    padding-top:8px;
}
.bottom {
    padding-bottom:8px;
}
.title {
    height: 30px;
    line-height: 30px;
     160rpx;
    text-align: center;
    display: inline-block;
    font: 300 28rpx/30px "microsoft yahei";
}
 
.input_base {
    border: 2rpx solid #ccc;
    padding-left: 10rpx;
    margin-right: 50rpx;
}
.input_h30{
    height: 30px;
    line-height: 30px;
}
.input_h60{
    height: 60px;
}
.input_view{
    font: 12px "microsoft yahei";
    background: #fff;
    color:#000;
    line-height: 30px;
}
 
input {
    font: 12px "microsoft yahei";
    background: #fff;
    color:#000 ;
}
radio{
    margin-right: 20px;
}
.grid { display: -webkit-box; display: box; }
.col-0 {-webkit-box-flex:0;box-flex:0;}
.col-1 {-webkit-box-flex:1;box-flex:1;}
.fl { float: left;}
.fr { float: right;}
3.弹框index.js逻辑代码
Page({
  data: {
    showModalStatus: false
  },
  powerDrawer: function (e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
  },
  util: function(currentStatu){
    /* 动画部分 */
    // 第1步:创建动画实例 
    var animation = wx.createAnimation({
      duration: 200,  //动画时长
      timingFunction: "linear", //线性
      delay: 0  //0则不延迟
    });
    
    // 第2步:这个动画实例赋给当前的动画实例
    this.animation = animation;
 
    // 第3步:执行第一组动画
    animation.opacity(0).rotateX(-100).step();
 
    // 第4步:导出动画对象赋给数据对象储存
    this.setData({
      animationData: animation.export()
    })
    
    // 第5步:设置定时器到指定时候后,执行第二组动画
    setTimeout(function () {
      // 执行第二组动画
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象
      this.setData({
        animationData: animation
      })
      
      //关闭
      if (currentStatu == "close") {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)
  
    // 显示
    if (currentStatu == "open") {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
  }
 
})

三、案例运行效果图

微信小程序之自定义模态弹窗(带动画)实例第1张

 

免责声明:文章转载自《微信小程序之自定义模态弹窗(带动画)实例》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ActiveX控件的打包发布[无证书发布]NVIDIA Xavier 设置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

thinkphp6自定义指令

创建自定义指令操作步骤: 第一步:运行指令 php think make:command Auto auto 即可看到在 app\command 目录生成的 Auto.php  修改里面的代码: <?php declare (strict_types = 1); namespace app\command; use think\console\C...

input输入框内容规范正则总结

input type=text 只能输入数字(去掉e和小数点): <input type="number" onkeydown="return event.keyCode !== 69" /> <input type="text" onkeydown="return ( event.ctrlKey || event.altKey...

20201324 实验二《Python程序设计》实验报告

20201324 2020-2021-2 《Python程序设计》实验二报告 课程:《Python程序设计》 班级: 2013 姓名: 徐源 学号:20201324 实验教师:王志强 实验日期:2021年4月26日 必修/选修: 公选课 (一)实验内容 设计并完成一个完整的应用程序,完成加减乘除模等运算,功能多多益善。 基本四则运算 取模运算 求幂运算...

selenium关于断言的使用

基本介绍: Selenium工具专门为WEB应用程序编写的一个验收测试工具。 Selenium的核心:browser bot,是用JAVASCRIPT编写的。 Selenium工具有4种:Selenium IDE, Selenium Control, Selenium Core 这儿我们主要总结了Selenium-IDE工具 Selenium-IDE只限于...

PHP WEB安全问题

规则 1:绝不要信任外部数据或输入 关于 Web 应用程序安全性,必须认识到的第一件事是不应该信任外部数据。外部数据(outside data) 包括不是由程序员在 PHP 代码中直接输入的任何数据。在采取措施确保安全之前,来自任何其他来源(比如 GET 变量、表单 POST、数据库、配置文件、会话变量或 cookie)的任何数据都是不可信任的。 例如,下...

android自定义控件概述

引子:   android SDK中会提供一些基础的控件以供开发。但是大多数情况下,这些基础的控件无法满足业务需求。本文主要说明自定义控件的分类,以及提供示例代码。   本文只做入门级选手阅读,或者 加深印象 或 温故而知新,大佬大神敬请绕道。 android控件的3种方式: 1)派生控件 : 从SDK已有的控件为基础,改变其部分特征,形成符合需求的自定...