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

效果图

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

HTML


<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>

CSS

/*使屏幕变暗  */
.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)
  }


})
  • 19
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
UniApp 是一个使用 Vue.js 开发跨平台应用的前端框架,它支持将代码一次编写,即可发布到多个平台,包括微信小程序。在 UniApp 中,自定义底部 tabbar 非常简单,只需要在 pages.json 中指定 tabBar 配置,然后在页面中使用自己的自定义 tabbar 组件即可。 以下是自定义底部 tabbar 的步骤: 1. 在 pages.json 文件中设置 tabBar 配置,如下所示: ```javascript { "tabBar": { "custom": true, // 使用自定义的tabBar "color": "#7A7E83", "selectedColor": "#3cc51f", "backgroundColor": "#ffffff", "borderStyle": "white", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "/static/tabbar/home.png", "selectedIconPath": "/static/tabbar/home-active.png" }, { "pagePath": "pages/user/user", "text": "我的", "iconPath": "/static/tabbar/user.png", "selectedIconPath": "/static/tabbar/user-active.png" } ] } } ``` 2. 在页面中引入自己的自定义 tabbar 组件,并使用该组件替换默认的 tabBar,如下所示: ```javascript <template> <view> <router-view /> <my-tab-bar :list="list" :active.sync="active" /> </view> </template> <script> import MyTabBar from '@/components/MyTabBar.vue' export default { components: { MyTabBar }, data () { return { active: 0, list: [ { text: '首页', icon: '/static/tabbar/home.png', selectedIcon: '/static/tabbar/home-active.png', path: '/pages/index/index' }, { text: '我的', icon: '/static/tabbar/user.png', selectedIcon: '/static/tabbar/user-active.png', path: '/pages/user/user' } ] } } } </script> ``` 以上是自定义底部 tabbar 的简单介绍,如果您需要更详细的内容,请查看 UniApp 的官方文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值