博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【微信小程序】自定义模态框实例
阅读量:4567 次
发布时间:2019-06-08

本文共 2542 字,大约阅读时间需要 8 分钟。

原文链接:https://mp.weixin.qq.com/s/23wPVFUGY-lsTiQBtUdhXA

1

概述

由于官方API提供的显示模态弹窗,只能简单地显示文字内容,不能对对话框内容进行自定义,欠缺灵活性,所以自己从模态弹窗的原理角度来实现了自定义的模态对话框。今天我们就分享这样的小教程。希望对大家有所帮助。

不多说了,二当家要上图来啦!

快去拿个小板凳,坐等更多更新

注意:如若需要请联系微信geekxz

2

wxml

 
 
添加数量
 
   
     
   
 
 
   
取消
   
确定
 

3

  js

Page({
   data: {
     showModal: false,    },    onLoad: function () {
   },    /**     * 弹窗     */    showDialogBtn: function() {
     this.setData({
       showModal: true      })    },    /**     * 弹出框蒙层截断touchmove事件     */    preventTouchMove: function () {
   },    /**     * 隐藏模态对话框     */    hideModal: function () {
     this.setData({
       showModal: false      });    },    /**     * 对话框取消按钮点击事件     */    onCancel: function () {
     this.hideModal();    },    /**     * 对话框确认按钮点击事件     */    onConfirm: function () {
     this.hideModal();    } })

4   css

.show-btn {
 margin-top: 100rpx;  color: #22cc22; } .modal-mask {
 width: 100%;  height: 100%;  position: fixed;  top: 0;  left: 0;  background: #000;  opacity: 0.5;  overflow: hidden;  z-index: 9000;  color: #fff; } .modal-dialog {
 width: 540rpx;  overflow: hidden;  position: fixed;  top: 50%;  left: 0;  z-index: 9999;  background: #f9f9f9;  margin: -180rpx 105rpx;  border-radius: 36rpx; } .modal-title {
 padding-top: 50rpx;  font-size: 36rpx;  color: #030303;  text-align: center; } .modal-content {
 padding: 50rpx 32rpx; } .modal-input {
 display: flex;  background: #fff;  border: 2rpx solid #ddd;  border-radius: 4rpx;  font-size: 28rpx; } .input {
 width: 100%;  height: 82rpx;  font-size: 28rpx;  line-height: 28rpx;  padding: 0 20rpx;  box-sizing: border-box;  color: #333; } input-holder {
 color: #666;  font-size: 28rpx; } .modal-footer {
 display: flex;  flex-direction: row;  height: 86rpx;  border-top: 1px solid #dedede;  font-size: 34rpx;  line-height: 86rpx; } .btn-cancel {
 width: 50%;  color: #666;  text-align: center;  border-right: 1px solid #dedede; } .btn-confirm {
 width: 50%;  color: #ec5300;  text-align: center; }

以上代码效果

文末福利:

福利一:前端,Java,产品经理,微信小程序,Python等100G资源合集大放送:

福利二:微信小程序入门与实战全套详细视频教程。

【领取方法】

关注 【编程微刊】微信公众号:

回复【小程序demo】一键领取130个微信小程序源码demo资源。

回复【领取资源】一键领取前端,Java,产品经理,微信小程序,Python等资源合集100G资源大放送。

转载于:https://www.cnblogs.com/wangting888/p/9701517.html

你可能感兴趣的文章
浅谈.NET(C#)与Windows用户账户信息的获取
查看>>
C语言库函数大全及应用实例十一
查看>>
WCF常见问题(1) -- WebService/WCF Session Cookie
查看>>
SQL Server 连接问题-命名管道
查看>>
《BI那点儿事》Microsoft 顺序分析和聚类分析算法
查看>>
设计模式之五(策略模式)
查看>>
Matlab.NET混合编程技巧之——直接调用Matlab内置函数(附源码)
查看>>
C#实现屏幕录像
查看>>
WebBrowser脚本错误的完美解决方案
查看>>
.NET Framework 3.5-8 下载地址
查看>>
透明背景,字体不透明
查看>>
理解爬虫原理
查看>>
How to Succeed in Graduate School: A Guide for Students and Advisors-1
查看>>
laravel开发之-php artisan命令
查看>>
Unity UGUI知识点
查看>>
全排列函数
查看>>
poj2195Going Home(最小费用最大流)
查看>>
Oracle回收站的清理方法
查看>>
CentOS 7.2 (mini) 里iptables防火墙怎么关闭?
查看>>
怎样关闭“粘滞键”?
查看>>