描述

模仿ios浏览器底部弹框效果。

遮罩层淡入淡出,弹框高度根据内容自适应。

效果


源码

popup-bottom.wxml

<!-- popup-bottom.wxml -->
<view class="wrap" hidden="{{!myVisible}}">
<view class="mask {{visible ? 'mask-show' : ''}}" bindtap="_onCancel"></view>
<view class="box" id="modal-box" animation="{{animationData}}">
<slot />
</view>
</view>

popup-bottom.js

// popup-bottom.js
Component({
properties: {
myVisible: {
type: Boolean,
value: false,
observer: '_visibleChange',
},
}, data: {
visible: false,
animation: null,
animationData: null,
}, ready: function () {
const animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0,
});
this.setData({
animation,
})
}, methods: {
_visibleChange: function (newVal, oldVal, changedPath) {
if (oldVal === false && newVal === true) {
setTimeout(function () {
this._onShow();
}.bind(this), 0)
}
}, _onShow: function () {
const __this = this;
const query = wx.createSelectorQuery().in(this);
query.select('#modal-box').boundingClientRect(function (res) {
const { animation } = __this.data;
animation.translateY(-res.height).step();
__this.setData({
visible: true,
animationData: animation.export(),
})
}).exec();
}, _onCancel: function () {
const { animation } = this.data;
animation.translateY(0).step();
this.setData({
visible: false,
animationData: animation.export(),
})
setTimeout(function () {
this.triggerEvent('myOnCancel');
}.bind(this), 200)
}, },
})

popup-bottom.wxss

/* popup-bottom.wxss */
.wrap {
position: fixed;
left: 0;
top: 0;
z-index: 99999;
width: 100vw;
height: 100vh;
} .mask {
position: fixed;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
transition: 0.2s;
}
.mask-show {
opacity: 0.4;
} .box {
position: fixed;
top: 100vh;
left: 0;
z-index: 2;
width: 100%;
min-height: 100rpx;
background: #fff;
}

popup-bottom.json

{
"component": true,
"usingComponents": {}
}

使用

test.wxml

<button bindtap="handleShow">点我弹出popup</button>
<popup-bottom myVisible="{{visible}}" bindmyOnCancel="handleCancel">
<view>我是内容</view>
<view>我是内容</view>
<view>我是内容</view>
<view>我是内容</view>
<view>我是内容</view>
</popup-bottom>

test.js

Page({
data: {
visible: false,
}, handleShow: function () {
this.setData({ visible: true });
}, handleCancel: function () {
this.setData({ visible: false });
},
})

test.json

{
"navigationBarTitleText": "底部弹框",
"usingComponents": {
"popup-bottom": "/components/popup-bottom/popup-bottom"
}
}

[组件封装]微信小程序-底部弹框的更多相关文章

  1. 微信小程序底部弹框动画

    在写小程序的时候,一般会碰到底部弹出动画,就像下面这样的效果 直接进入正题 https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-animation.ht ...

  2. 关于微信小程序 modal弹框组件的介绍

    微信小程序 modal: 这里对微信小程序中 modal组件进行详细解析,我想开发微信小程序的小伙伴可以用到,这里小编就记录下modal的知识要点. modal modal类似于javascript中 ...

  3. [组件封装]微信小程序-图片批量上传照片墙

    描述 批量上传图片, 可设置最大上传个数, 可删除, 可设置默认值. 效果 源码 pictures-wall.wxml <view class="picturesWall"& ...

  4. 微信小程序之----弹框组件modal

    modal modal类似于javascript中的confirm弹框,默认情况下是一个带有确认取消的弹框,不过点击取消后弹框不会自动隐藏,需要通过触发事件调用函数来控制hidden属性. 官方文档 ...

  5. 【组件】微信小程序input搜索框的实现

    开发小程序的过程,是一个学习知识,解决问题的过程,每当实现了一个需求,总会有很大的成就感,每天记录一个开发过程中的细节.实现效果如下: 官方参考链接:https://developers.weixin ...

  6. 微信小程序 --- model弹框

    model弹框:在屏幕中间弹出,让你进行选择: 效果: 代码: <button type="primary" bindtap="btnclick"> ...

  7. [组件封装]微信小程序-日历

    描述 切换月份, 当天文案为今天, 日期背景变色, 日期红点标识, 点击选中日期. 效果 源码 calendar.wxml <view class="component"&g ...

  8. 微信小程序之弹框modal

    官方文档 <modal hidden="{{hidden}}" title="这里是title" confirm-text="自定义确定按钮&q ...

  9. 详解封装微信小程序组件及小程序坑(附带解决方案)

    一.序 上一篇介绍了如何从零开发微信小程序,博客园审核变智障了,每次代码都不算篇幅,好好滴一篇原创,不到3分钟从首页移出来了.这篇介绍一下组件封装和我的踩坑历程. 二.封装微信小程序可复用组件 首先模 ...

随机推荐

  1. 我在linux的第一个C程序

    今天在虚拟机装起了linux,根据大家学习所需要,可以安装自己喜欢的版本,我这里装的是centos 7.0版本,也正是学习的开始,现在来看看简洁大气的centos界面吧:     在centos编译C ...

  2. shell的循环嵌套语法

    测试shell的循环嵌套语法 [root@localhost test]# vi Xunhuanqiantao.sh #!/bin/bash #程序功能描述: # 测试循环嵌套 #作者:孤舟点点 #版 ...

  3. python Post 登录 cookies 和session

    def post_name(): print('\npost name') # http://pythonscraping.com/pages/files/form.html data = {'fir ...

  4. sycCMS PHP V1.0---呵呵呵呵呵

    闲的无聊,随便找了份代码看了看. //search.php 第17行 第49行 ...... $keyword=SafeRequest("keyword","post&q ...

  5. Sed 实记 · laoless's Blog

    sed编辑命令 p 打印匹配行 = 打印文件行号 a 在定位行之后追加文本 i 在定位行之前插入文本 d 删除定位行 c 用新文本替换定位文本 s 使用替换模式替换相应模式 r 从另一个文件读取文本 ...

  6. 前端开发个人小结 · Retrospection的博客

    序 2018年转眼来到了最后一个月,算下来我进入前端之门也有一年了,虽然下半年由于忙于筹备毕业论文的相关事项,前端这一块有所放下,但是想想还是给自己这一年的学习做一个总结. 现代化软件开发确实是一个复 ...

  7. Mac 常见命令行

    1. unrar解压rar文件 1.1 安装命令:brew install unrar 1.2 解压文件:unrar x test.rar 2. 创建文件夹:mkdir 文件夹名 3. 删除文件夹: ...

  8. python 读取 execl 文件 之 xlrd 模块

    1. 安装 xlrd模块 pip install xlrd 2. 读取文件内容 #!/usr/bin/env python3 import xlrd name = r"E:\excel\yo ...

  9. 使用GitHub(二):配置并使用Git创建版本库

    使用GitHub(二):配置并使用Git创建版本库 本文简单介绍使用GitHub对代码进行版本控制,包括添加SSHkey.配置Git.使用Git创建版本库并在GitHub上进行管理,主要目的是对学习内 ...

  10. 前端每日实战:1# 视频演示如何用纯 CSS 创作一个按钮文字滑动特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/zhang-ou/pen/GdpPLE 可交互视频教程 此视频 ...