[组件封装]微信小程序-底部弹框
描述
模仿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"
}
}
[组件封装]微信小程序-底部弹框的更多相关文章
- 微信小程序底部弹框动画
在写小程序的时候,一般会碰到底部弹出动画,就像下面这样的效果 直接进入正题 https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-animation.ht ...
- 关于微信小程序 modal弹框组件的介绍
微信小程序 modal: 这里对微信小程序中 modal组件进行详细解析,我想开发微信小程序的小伙伴可以用到,这里小编就记录下modal的知识要点. modal modal类似于javascript中 ...
- [组件封装]微信小程序-图片批量上传照片墙
描述 批量上传图片, 可设置最大上传个数, 可删除, 可设置默认值. 效果 源码 pictures-wall.wxml <view class="picturesWall"& ...
- 微信小程序之----弹框组件modal
modal modal类似于javascript中的confirm弹框,默认情况下是一个带有确认取消的弹框,不过点击取消后弹框不会自动隐藏,需要通过触发事件调用函数来控制hidden属性. 官方文档 ...
- 【组件】微信小程序input搜索框的实现
开发小程序的过程,是一个学习知识,解决问题的过程,每当实现了一个需求,总会有很大的成就感,每天记录一个开发过程中的细节.实现效果如下: 官方参考链接:https://developers.weixin ...
- 微信小程序 --- model弹框
model弹框:在屏幕中间弹出,让你进行选择: 效果: 代码: <button type="primary" bindtap="btnclick"> ...
- [组件封装]微信小程序-日历
描述 切换月份, 当天文案为今天, 日期背景变色, 日期红点标识, 点击选中日期. 效果 源码 calendar.wxml <view class="component"&g ...
- 微信小程序之弹框modal
官方文档 <modal hidden="{{hidden}}" title="这里是title" confirm-text="自定义确定按钮&q ...
- 详解封装微信小程序组件及小程序坑(附带解决方案)
一.序 上一篇介绍了如何从零开发微信小程序,博客园审核变智障了,每次代码都不算篇幅,好好滴一篇原创,不到3分钟从首页移出来了.这篇介绍一下组件封装和我的踩坑历程. 二.封装微信小程序可复用组件 首先模 ...
随机推荐
- Spring+Struts2+Mybatis整合
1. 创建项目 2. 添加Spring能力 使用MyEclipse自动加载Struts2和Spring的jar包和配置文件,并在web.xml文件中添加上下文和监听器 web.xml文件如下: < ...
- docker实践-安装wordpress
很多人都有搭建wordpress的经历,可能被某些环境的配置搞得焦头乱耳的,这里使用docker,可以很轻松的进行wordpress的搭建工作. 安装 Docker sudo apt-get inst ...
- 中文字体压缩器-解决css引入的字体太大的问题
字蛛是一个中文字体压缩器 官方网站:http://font-spider.org/index.html 用于解决页面引入的css字体过大的问题 使用方法: npm i -g font-spider 在 ...
- Golang: chan定义问题(7)
通常都是定义读写双向的 chan,定义单向 chan 问题. 专栏的介绍可以参考 <GotchaGolang专栏>,代码可以看<宝库-Gotcha>. 通过 只写 chan 传 ...
- Android入门(创建、编译、运行、打包、安装)
一.创建Android项目 1.选择Emtpy Activity=>Next 2.配置项目 输入Name(名称) Package.name(包名) Save location(保存位置) Lan ...
- 牛客网剑指offer第21题——判断出栈序列是否是入栈序列
题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈 ...
- 启动tomcat报错 Unable to process Jar entry [module-info.class] from Jar...[xxx.xx.jar!\] for annotations
Java Web 项目tomcat启动报错module-info.class 从git 上面拉下的项目,运行报错. jdk.maven配置正常 tomcat启动遇见的问题: Unable to pro ...
- DroidVim:在安卓手机上使用vim
背景 有时候在邮件,钉钉,微信上收到一份文件,急需打开看一下,但有些文件用普通编辑器打开体验实在不佳,例如 patch,log 甚至 bin 文件.由于日常在电脑上使用的是 vim ,一个朴素的想法就 ...
- vue+webpack怎么分环境进行打包
这里说下,webpack打包里面涉及到的东西,不止webpack,还有node的知识, node的全局变量process,process.env用于返回用户环境信息对象,因为是node的全局变量,所以 ...
- Educational Codeforces Round 83 (Rated for Div. 2)A--C
题意:给出一个边数为n的等边多边形,问是否可以变成m的等边多边形.条件是同一个中心,共用原顶点. 解析:直接n%m==0即可,这样就是平分了.签到题没得说了. #include<iostream ...