微信小程序底部自定义弹窗

 效果图

 

 wxml:

<view bindtap="clickme">点击我可以看到底部弹框的出现</view>  
 
<!--屏幕背景变暗的背景  -->
  <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view>
  <!--弹出框  -->
  <view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}">在这里写弹出框里面的布局</view>

wxss:

/*使屏幕变暗  */
.commodity_screen {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: #000;
  opacity: 0.2;
  overflow: hidden;
  z-index: 1000;
  color: #fff;
}
/*对话框 */
.commodity_attr_box {
  height: 300rpx;
  width: 100%;
  overflow: hidden;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 2000;
  background: #fff;
  padding-top: 20rpx;
}

js:

Page({
  data: {
 
  },
 
  onLoad: function (options) {
  },
  //点击我显示底部弹出框
  clickme: function () {
    this.showModal();
  },
 
  //显示对话框
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  }
 
 
})

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
微信小程序中的Picker组件是一个内置的下拉控件,它提供了一些默认样式和功能。如果需要自定义下拉弹窗的样式,可以使用自定义组件实现。 以下是一个示例代码,演示如何使用自定义组件实现自定义下拉弹窗样式: 1. 在小程序根目录下创建一个名为 "custom-picker" 的自定义组件文件夹,并在该文件夹下创建一个名为 "custom-picker.wxml" 的模板文件。 2. 在 custom-picker.wxml 文件中编写下拉弹窗的结构和样式,例如: ```html <view class="picker-container"> <view class="header"> <text class="cancel" bindtap="onCancel">取消</text> <text class="title">{{title}}</text> <text class="confirm" bindtap="onConfirm">确定</text> </view> <picker class="picker" value="{{value}}" range="{{range}}" bindchange="onChange"></picker> </view> ``` 3. 在 custom-picker.js 文件中编写自定义组件的逻辑,例如: ```javascript Component({ properties: { title: String, value: Number, range: Array }, methods: { onCancel: function() { this.triggerEvent('cancel'); }, onConfirm: function() { this.triggerEvent('confirm', { value: this.data.value }); }, onChange: function(e) { this.setData({ value: e.detail.value }); } } }); ``` 4. 在使用该自定义组件的页面中,引入该组件并传入相应的属性,例如: ```html <custom-picker title="请选择" value="{{index}}" range="{{range}}" bind:cancel="onPickerCancel" bind:confirm="onPickerConfirm"></custom-picker> ``` 5. 在页面的 js 文件中编写相应的逻辑,例如: ```javascript Page({ data: { range: ['选项一', '选项二', '选项三'], index: 0 }, onPickerCancel: function() { // 取消选择 }, onPickerConfirm: function(e) { const value = e.detail.value; // 确认选择 } }); ``` 通过以上步骤,就可以实现自定义下拉弹窗的样式和功能。需要注意的是,自定义组件的样式和逻辑都需要自行编写。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小马大咖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值