• 微信小程序实现弹窗效果


    实现思路

    模态对话框之所以被叫做“模态”,就是因为在它弹出的时候,用户如果不关闭这个对话框,是无法对其他窗口进行操作的。
    那么这样一来,我们的思路就很明确了:

    1. 构建一个蒙层(mask),使得背景变暗,并且阻止用户对对话框外界面的这里写代码片点击事件;
    2. 构建一个对话框,在需要时弹出即可(弹出同时触发蒙层)。

    .wxml:

    <view class="mask" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
    
    <view class="modalDlg" wx:if="{{showModal}}">
     <view bindtap="closeMask" class="modal-close">x</view>
     <image src="/assets/images/newer.gif"/>
    </view>
    
    <button bindtap="submit">点我弹窗</button>

    .wxss:

    .mask{
      width: 100%;
      height: 100%;
      position: fixed;
      top: 0;
      left: 0;
      background: #000;
      z-index: 9000;
      opacity: 0.7;
     }
     
     .modalDlg{
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      z-index: 9999;
     }
    
     .modal-close {
       position: fixed;
       top: -30rpx;
       right: -15rpx;
       color: #ffffff;
     }

    .js:

    Page({
    
      data: {
        showModal: false
       },
       
       submit: function() {
        this.setData({
        showModal: true
        })
       },
       
       preventTouchMove: function() {
       
       },
       
       closeMask: function() { 
        this.setData({
        showModal: false
        })
       }
    })

    参考:https://www.jb51.net/article/143440.htm

  • 相关阅读:
    get通配符
    常用正则表达式(合)
    2.A star
    1.序
    机器人运动规划04《规划算法》
    机器人运动规划03什么是运动规划
    6.2 性能优化
    6.1 内存机制及使用优化
    5.9 热修复技术
    5.8 反射机制
  • 原文地址:https://www.cnblogs.com/cshaptx4869/p/13306919.html
Copyright © 2020-2023  润新知