[组件封装]微信小程序-底部弹框
描述
模仿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分钟从首页移出来了.这篇介绍一下组件封装和我的踩坑历程. 二.封装微信小程序可复用组件 首先模 ...
随机推荐
- Trie图 模板
trie图实际上是优化的一种AC自动机. trie图是在trie树上加一些失配指针,实际上是类似KMP的一种字符串匹配算法. 失配指针类似KMP的nx数组,有效地利用了之前失配的信息,优化了时间复杂度 ...
- 吴裕雄--天生自然 R语言开发学习:主成分分析和因子分析(续一)
#--------------------------------------------# # R in Action (2nd ed): Chapter 14 # # Principal comp ...
- <JZOJ5907>轻功
dp大水题 由于未知错误wa了一个点 乱改了一下就A了 瘫 #include<cstdio> #include<iostream> #include<cstring> ...
- 主成分分析(PCA)模型概述
数据降维 降维是对数据高维度特征的一种预处理方法.降维是将高维度的数据保留下最重要的一些特征,去除噪声和不重要的特征,从而实现提升数据处理速度的目的.在实际的生产和应用中,降维在一定信息损失范围内,可 ...
- python中字典dic详解-创建,遍历和排序
原文地址:http://www.bugingcode.com/blog/python_dic_create_sort.html 在python的编程中,字典dic是最典型的数据结构,看看如下对字典的操 ...
- mysqldump免密备份方法
注意:1.暂时只试验了root用户 2.暂时只试验了5.6和5.7两个版本 1.我用的root用户,先进入家目录 cd ~ 2.vim .my.cnf #在家目录添加该文件 [mysqldum ...
- 详解服务器性能测试的全生命周期?——从测试、结果分析到优化策略(转载)
服务器性能测试是一项非常重要而且必要的工作,本文是作者Micheal在对服务器进行性能测试的过程中不断摸索出来的一些实用策略,通过定位问题,分析原因以及解决问题,实现对服务器进行更有针对性的优化,提升 ...
- Alberto Del Bimbo:为什么说研究员要有想象力?
Del Bimbo:为什么说研究员要有想象力?" title="Alberto Del Bimbo:为什么说研究员要有想象力?"> 说到科研,与日本式的&q ...
- Python爬虫-百度模拟登录(二)
上一篇-Python爬虫-百度模拟登录(一) 接上一篇的继续 参数 codestring codestring jxG9506c1811b44e2fd0220153643013f7e6b1898075 ...
- Python爬虫开发教程
正文 现在Python语言大火,在网络爬虫.人工智能.大数据等领域都有很好的应用.今天我向大家介绍一下Python爬虫的一些知识和常用类库的用法,希望能对大家有所帮助.其实爬虫这个概念很简单,基 ...