微信小程序创建自定义带图标的底部弹框

正常情况下,小程序中要从页面底部弹出选择框的话,首要选择是

wx.showActionSheet({
itemList: ['A', 'B', 'C'],
      success: function(res) {
      }
}

该方法运行后样式在iOS机子上显示为如下图,在android机子上显示的是没有“取消”按钮的,并且弹出框并不在页面底部,而是在页面中间。
在这里插入图片描述
现在我想要的效果是在A B C每一项选项前面各添加一个图标,但是不知道wx.showActionSheet这种方法应该怎么实现,所以换了另外一种实现方式:
在页面上定义一个按钮给一个点击事件,然后定义要弹出的页面布局:

<view class="page">
    <form class="page__bd">
      <view class="button-sp-area">
        <button class="weui-btn mini-btn" bindtap="dialogBottom" style="width:170px;" type="default" size="mini">
          弹出选择框
        </button>
        <!--以下是弹出框中要显示的内容-->
        <view class='classcommon1' animation="{{animationData}}" hidden="{{!isShowModal}}">
          <view class="classcommon2" id="pay" type="default" size="mini" bindtap="payWX">
            <image src='/utils/images/ico-wx.png'></image>
            微信支付
          </view>
          <view class="classcommon2" id="pay" type="default" size="mini" bindtap="payZFB">
            <image src='/utils/images/ico-zfb.png'></image>
            支付宝支付
          </view>
          <view class="classcommon2" id="pay" type="default" size="mini" bindtap="hideModal">
            取消
          </view>
        </view>
      </view>
    </form>
.classcommon1{
  width: 100%;
  height: 300rpx;
  background-color: white;
  margin-bottom: -153px;
  position: fixed;
  bottom: 0;
}

.classcommon2{
  color: black;
  text-align: center;
  height: 100rpx;
  width: 100%;
  line-height: 100rpx;
  border-bottom: 1rpx solid #f7f7f7;
}

在js文件中实现定义的点击事件,在页面的data中定义变量,此时就可以对弹窗的每一项点击事件加以实现了

    animationData: {},
    isShowModal: false,


  dialogBottom: function() {
    var that = this;
    that.data.animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease',
    })
    this.animation = that.data.animation
    that.data.animation.translate(0, -153).step();
    this.setData({
      animationData: that.data.animation.export(),
      isShowModal: true
    })
  },
  hideModal: function() {
    var that = this;
    that.data.animation.translate(0, 0).step();
    this.setData({
      animationData: that.data.animation.export()
    })
  },
  payWX: async function () {
    conssole.log('选了微信')
  },
  payZFB: function() {
    console.log('选了支付宝')
  },

此时的样式如下
在这里插入图片描述
总觉得使用此种方式还是很麻烦,不知道微信有没有提供类似于wx.showActionSheet这种的简洁能实现的方式,网上搜了大多数都是不带图标的,有其他方式能实现的话还请网友分享一下谢谢了哈

20200402补充
在这里插入图片描述
以上这种方式在页面上使用时,若页面最外面是view,则会导致在弹出弹框的同时后面页面的内容过长时是可以上下滑动,而且页面内容会与弹框内容重叠而导致看不清啥是啥(如上),若页面最外面是scroll-view则可通过弹出弹框时设置页面scroll-y为false禁止页面滑动,等弹框关闭时再设置解除就行。还有一种方法,参考代码片段https://developers.weixin.qq.com/s/vm87Kjm87qgX
效果如下:
在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值