微信小程序实现底部操作栏

底部操作栏实现功能:悬浮于页面底部。

底部操作栏会遮挡页面底部一部分的内容,可以通过给这部分内容设置和底部操作栏一样高度的 padding-bottom 来解决。

请添加图片描述

<!-- action-bar.wxml -->
<view class="container">
  <view class="action-bar">
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
  </view>
  <!-- 兼容 iPhone X 之后机型的安全区域问题,否则底部横条将会遮挡底部操作栏。实现思路是设置一个自定义组件填充此处的安全距离 -->
  <safe-dsitance direction='bottom'></safe-dsitance>
</view>

/* action-bar.wxss */
.container {
  width: 100%;
  padding: 30rpx;
  box-sizing: border-box;
  background: #fff;
  border-top: 2rpx solid #efefef;
  /* 悬浮于页面底部 */
  position: fixed;
  bottom: 0;
  z-index: 99;
}

.action-bar {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

{
  "component": true,
  "usingComponents": {
    "safe-dsitance": "/components/safe-distance/safe-distance"
  }
}
<!-- safe-distance.wxml -->
<view class="safe-distance-bottom"></view>

/* safe-distance.wxss */
.safe-distance-bottom {
  width: 100%;
  // 苹果官方提供的两个 CSS 函数:constant() (兼容 IOS < 11.2)和 env() (兼容 IOS >= 11.2)用于获取安全区域与边界的距离。
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在微信小程序实现底部导航,需要按照以下步骤进行操作: 1. 在 app.json 文件中设置底部导航的样式和内容。具体来说,在 app.json 文件中的 tabBar 属性中设置导航的样式和包含的页面路径,例如: ``` "tabBar": { "color": "#999", "selectedColor": "#007aff", "backgroundColor": "#f7f7f7", "borderStyle": "black", "list": [{ "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/tabbar/home.png", "selectedIconPath": "images/tabbar/home_selected.png" },{ "pagePath": "pages/order/order", "text": "订单", "iconPath": "images/tabbar/order.png", "selectedIconPath": "images/tabbar/order_selected.png" },{ "pagePath": "pages/mine/mine", "text": "我的", "iconPath": "images/tabbar/mine.png", "selectedIconPath": "images/tabbar/mine_selected.png" }] } ``` 2. 在 app.js 文件中添加监听函数,用于处理底部导航的点击事件。具体来说,在 app.js 文件中的 onTabItemTap 函数中添加相应的逻辑代码,例如: ``` App({ onLaunch: function () { // ... }, onTabItemTap: function(item) { console.log('tap tab item', item.index, item.pagePath) } }) ``` 3. 在需要使用底部导航的页面中添加相应的代码。具体来说,在需要使用底部导航的页面中,需要将页面的配置文件中的 navigationBarHidden 属性设置为 true,同时在页面的 WXML 文件中添加一个 tabbar 组件,例如: ``` <tabbar selected="{{selected}}" bindchange="tabbarChange"> <tabbar-item key="home" icon="{{homeIcon}}" selected-icon="{{homeSelectedIcon}}"> <view wx:slot="text">首页</view> </tabbar-item> <tabbar-item key="order" icon="{{orderIcon}}" selected-icon="{{orderSelectedIcon}}"> <view wx:slot="text">订单</view> </tabbar-item> <tabbar-item key="mine" icon="{{mineIcon}}" selected-icon="{{mineSelectedIcon}}"> <view wx:slot="text">我的</view> </tabbar-item> </tabbar> ``` 其中,selected 表示当前选中的 tabbar-item 的 key 值,bindchange 表示 tabbar-item 点击事件的处理函数。 以上就是在微信小程序实现底部导航的基本步骤,需要注意的是,开发者需要根据实际需求进行样式和逻辑的调整,以达到最佳的用户体验效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值