[组件封装]微信小程序-底部弹框
描述
模仿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分钟从首页移出来了.这篇介绍一下组件封装和我的踩坑历程. 二.封装微信小程序可复用组件 首先模 ...
随机推荐
- Algorithms第3章及少量习题
第三章的主要思想就是DFS.讲了图上的DFS操作,然后讲了各种应用.这章默认图都是用邻接矩阵存的. procedure explore(G, v) Input: G = (V, E) is a gra ...
- 探究 Go 语言 defer 语句的三种机制
Golang 的 1.13 版本 与 1.14 版本对 defer 进行了两次优化,使得 defer 的性能开销在大部分场景下都得到大幅降低,其中到底经历了什么原理? 这是因为这两个版本对 defer ...
- Ueditor富文本编辑器--Ctrl V 粘贴后原有图片显示错误
最近负责将公司官网从静态网站改版成动态网站,方便公司推广营销人员修改增加文案,避免官网文案维护过于依赖技术人员.在做后台管理系统时用到了富文本编辑器Ueditor,因为公司有一个阿里云文件资源服务器, ...
- iOS 开发富文本之TTTAttributedLabel 在某个特定位置的文字添加跳转,下划线,修改字体大小,颜色
@property(nonatomic , strong) TTTAttributedLabel * ttLabel; @property(nonatomic , strong) NSRange li ...
- Dart的JIT 与 AOT
JIT:Just In Time AOT:Ahead of Time 含义: 目前,程序主要有两种运行方式:静态编译与动态解释. 静态编译的程序在执行前全部被翻译为机器码,通常将这种类型称为AOT ( ...
- vue-router03 vue-cli
1.钩子: next讲解: next()进行路由跳转 next(false)取消路由跳转 beforeRouteEnter (to, from, next) { next(vm => { // ...
- Linux学习资料地址汇总-不定时更(一)
https://linux.linuxidc.com/ 用户名和密码都是www.linuxidc.com
- Go性能分析大杀器PPROF
这是什么 想要进行性能优化,Go本身自带的工具链就包含了性能分析工具,而且也非常棒,pprof就是Go性能分析的利器,它是Go语言自带的包,有如下两种: runtime/pprof:采集程序(非 Se ...
- 运维介绍以及虚拟机,centos安装
运维的职责 1.企业的数据安全 2.网站7*24小时运行 3.企业服务好 服务器 服务器尺寸: 高度为单位:U(unit)1U=1.75英寸=4.45cm 服务器的分类: 机架式服务器 刀片式服务器 ...
- python字符串的常见操作
find: 根据指定字符串获取对应的下标, 如果找不到对应的数据返回-1, 这里的-1表示没有找到数据 my_str = "hello" # find: 根据指定字符串获取对应的下 ...