微信小程序自定义弹窗/弹出层功能,非官方api

微信小程序自定义弹窗/弹出层功能,非官方api

index.html

<!--index.wxml-->
<!-- 遮罩层 -->
<view class="mask" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
<!-- 弹出层 -->
<view class="modalDlg" wx:if="{{showModal}}">
<!-- 二维码或其他图片 -->
    <image src="../images/gzhewm.png"/>
    <text class="text">这里是文本描述,可以查看css修改样式</text>
    <view bindtap="ok" class="ok">好的</view>
</view>
<view bindtap="btn" class="btn">弹窗</view>

index.css

/**index.wxss**/
/* 外面的按钮 */
.btn{
  width: 80px;
  height: 35px;
  background: #44b549;
  line-height: 35px;
  text-align: center;
  color: #fff;
  font-size: 15px;
  margin:20px auto;
  border-radius: 100px; 
}
 
/* 遮罩层 */
.mask{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #000;
    z-index: 9000;
    opacity: 0.5;
}
  
/* 弹出层 */
.modalDlg{
    width: 70%;
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    z-index: 9999;
    margin: 0 auto;
    background-color: #fff;
    border-radius:5px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
 
/* 弹出层里面的图片 */
.modalDlg image{
  width: 120px;
  height: 120px;
  margin-top: 30px;
}
 
/* 弹出层里面的按钮 */
.ok{
  width: 80px;
  height: 35px;
  background: #44b549;
  line-height: 35px;
  text-align: center;
  color: #fff;
  font-size: 15px;
  margin:20px auto;
  border-radius: 100px;
}
 
/* 弹出层里面的文字 */
.text{
  text-align: justify;
  font-size: 14px;
  color: #666;
  width: 180px;
  margin-top: 10px;
}

 

index.js

Page({
  data: {
    showModal: false
  },
 
  // 外面的弹窗
  btn: function () {
    this.setData({
      showModal: true
    })
  },
 
  // 禁止屏幕滚动
  preventTouchMove: function () {
  },
 
  // 弹出层里面的弹窗
  ok: function () {
    this.setData({
      showModal: false
    })
  }
 
})

 

 

 

原文链接:https://www.52pojie.cn/thread-804541-1-1.html

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值