小程序自定义弹出框效果
作者:蔬菜_ 发布时间:2023-07-02 03:47:33
标签:小程序,弹出框
本文实例为大家分享了小程序自定义弹出框效果的具体代码,供大家参考,具体内容如下
my-pop----api:
title ------字符串---------自定义弹窗标题
context ------字符串---------自定义弹窗内容
cancelTxt ------字符串---------取消按钮文本
cancelCor ------字符串---------取消按钮颜色
inp ------布尔值---------true文本弹出框---------fasle默认弹出框
okTxt ------字符串---------确定按钮文字
okCor ------字符串---------确定按钮颜色
@cancel ------事件---------点击取消按钮事件可携带value参数
@ok ------事件---------点击确定按钮事件可携带value参数
//使用方法
//在目标文件json文件里引入该组件
"usingComponents": {
"mypop":"/components/my-pop"
}
<mypop id="mypop" context="测试一下主体" inp="{{true}}" bindok="ok"/>
//给组件一个id
this.selectComponent("#mypop").openPop(); //打开弹窗
ok(e) //点击确定触发 如果是inp类型弹窗 e 就是input的value , 反之e为空串
cancel(e) //点击取消触发 如果是inp类型弹窗 e 就是input的value , 反之e为空串
弹窗js文件:
Component({
/**
* 组件的属性列表
*/
properties: {
title: {
type: String,
value: '默认标题',
},
context: {
type: String,
value: '默认内容',
},
inp:{
type: Boolean,
value: true
},
cancelTxt: {
type: String,
value: '取消',
},
cancelCor:{
type:String,
value:'black'
},
okTxt: {
type: String,
value: '确认',
},
okCor:{
type:String,
value:'red'
},
},
/**
* 组件的初始数据
*/
data: {
show:false,
animation:'',
animationPop:'',
inpVal:''
},
methods: {
bindinput(e){
let {value} = e.detail
this.setData({inpVal:value})
},
ok(){
this.triggerEvent("ok",this.data.inpVal);
this.hidePop()
this.setData({inpVal:''})
},
cancel(){
this.triggerEvent("cancel",this.data.inpVal);
this.hidePop()
this.setData({inpVal:''})
},
openPop(){
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.opacity(0).step()
this.setData({
animationData: animation.export(),
show:true
})
setTimeout(function () {
animation.opacity(1).step()
this.setData({
animationData: animation.export()
})
}.bind(this), 200)
},
hidePop(){
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.opacity(0).step()
this.setData({
animationData: animation.export()
})
setTimeout(function () {
this.setData({
show:false
})
}.bind(this), 200)
}
}
})
弹窗wxml文件:
<!--components/my-pop.wxml-->
<view>
<view class="mask" animation="{{animationData}}" bindtap="hidePop" wx:if="{{show}}">
<view class="content" animation="{{animationPop}}" catchtap >
<view class="title">{{title}}</view>
<view class="txt" wx:if="{{!inp}}">{{context}}</view>
<view class="inp" wx:if="{{inp}}">
<input type="text" value='{{inpVal}}' bindinput="bindinput" name="" id="" />
</view>
<view class="btnView">
<view class="cancel" hover-class="op5" bindtap="cancel" style="color:{{cancelCor}}">{{cancelTxt}}</view>
<view class="partition"></view>
<view class="ok" hover-class="op5" bindtap="ok" style="color:{{okCor}}">{{okTxt}}</view>
</view>
</view>
</view>
</view>
弹窗wxss文件:
.mask{
width: 100%;
height: 100vh;
position: fixed;
top: 0; left: 0;
z-index: 100;
background: rgba(0, 0, 0, 0.4);
display: flex;
align-items: center;
justify-content: center;
}
.content{
background: #FFFFFF;
border-radius: 16rpx;
width: 70%;
}
.title{
padding: 32rpx 0rpx;
text-align: center;
font-weight: 500;
font-size: 32rpx;
color: black;
}
.txt{
color: #000000;
font-size: 24rpx;
text-align: center;
margin-bottom: 32rpx;
}
.btnView{
border-top: 1rpx solid #D4D6D8;
display: flex;
align-items: center;
justify-content: space-around;
}
.cancel{
width: 49%;
display: flex;
align-items: center;
justify-content: center;
height: 80rpx; line-height: 80rpx;
}
.ok{
width: 49%;
display: flex;
align-items: center;
justify-content: center;
height: 80rpx; line-height: 80rpx;
}
.inp{
text-align: center;
padding: 5px 0px;
font-size: 24rpx;
margin: auto;
color: #868686;
width: 90%;
border: 1.2px solid #DEDEDE;
border-radius: 5px;
margin-bottom: 32rpx;
}
.op5{
opacity: .5;
background: rgba(0,0,0,0.05);
}
.partition{
width: 2rpx;
height: 80rpx;
background: #D4D6D8;
}
弹窗json文件:
{
"component": true,
"usingComponents": {}
}
来源:https://blog.csdn.net/hello917/article/details/105118070


猜你喜欢
- keras自定义函数时候,正常在模型里自己写好自定义的函数,然后在模型编译的那行代码里写上接口即可。如下所示,focal_loss和fbet
- 在做项目的时候,遇到这样的数据:"trends": [ { &nb
- 在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片。本人偏爱 matpoltlib,因为
- 本文实例讲述了sogou地图API应用,是非常实用的技巧。分享给大家供大家参考。具体实现方法如下:地图的初始化1、添加引用地图的API文件:
- 误区10.数据库镜像在故障发生后,马上就能发现 错误 市面上大肆宣传数据库镜像技术可以在故障发生后,立即检测到错误并进行故障转移。 但事实并
- c shell perl php下的日期时间转换: 秒数与人类可读日期 scalar localtime 与 seconds since `
- tips:如果根目录下有favicon.ico,可省去<link rel="shortcut icon" ...&
- 初学python,看来零零碎碎的格式化文本的方法,总结一下python中格式化文本的方法。使用不当的地欢迎指出谢谢。1、首先看使用%格式化文
- Spark GraphX是一个分布式图处理框架,基于 Pregel 接口实现了常用的图算法。包括 PageRank、SVDPlusPlus、
- 一般情况下TextArea区输入的文字数量是没有限制的,但是我们可以通过javascript限制表单的文字字数。如下javascript代码
- 笔者在今天的工作中,遇到了一个需求,那就是如何将Python字符串生成PDF。比如,需要把Python字符串‘这是测试文件'生成为P
- 可能是我“火星”了,不过在 空虚 的 Blog 中学到的一招。这个技巧的原理是利用 iframe 载入本机各盘符的根目录,然后判断 ifra
- 实例如下所示:# -*- coding: UTF-8 -*-from urllib import requestif __name__ ==
- MySQL分区方便了我们的使用,但是MySQL分区究竟能做些什么,MySQL分区有没有什么限制呢?阅读下文,您就能找到答案。MySQL分区能
- 注意:首先你电脑必须安装git版本控制器(软件),在官网下载即可。pycharm中使用git以及github很简单,首先在设置中搜索gith
- 本文实例为大家分享了python实现俄罗斯方块的具体代码,供大家参考,具体内容如下# teris.py# A module for game
- 最近被告知,MySQL主从数据库的数据不一致,猜测备库在同步过程中出现了问题,于是,登上备库,使用 mysql> show slave
- 位运算,赋值状态时异或对应位数1的整形,判断状态则与运算对应位数1的整形。最大用处就是同时判断32位状态,节省存储空间,便于扩展, 
- 第一步:下载mysql镜像镜像docker pull mysql默认是下载最新稳定版第二步:启动mysql镜像docker run --na
- Software as a service 软件即服务,21世纪开始兴起的一种完全创新的软件应用模式。客户通过互联网向厂商定购所需的应用软件