支付宝小程序实现自定义头部导航栏

53 篇文章 34 订阅

1.实现效果

在这里插入图片描述

2.实现原理

获取手机信息:

onLoad(query) {
 this.getSystemInfo()
},
getSystemInfo() {
  my.getSystemInfo({
    success: (res) => {
      this.setData({
        systemInfo: res
      })
    }
  })
},

在这里插入图片描述

statusBarHeight:状态栏高度
titleBarHeight:标题栏高度
在这里插入图片描述

3.实现代码

在json中设置

{
  "transparentTitle": "always"
}

关键代码

  <view class="custom_title flex-row" style="height:{{systemInfo.titleBarHeight}}px;padding-top:{{systemInfo.statusBarHeight}}px;" >hi,12312312312312~</view>
data: {
 systemInfo: {},
}
onLoad(query) {
 this.getSystemInfo()
},
getSystemInfo() {
  my.getSystemInfo({
    success: (res) => {
      this.setData({
        systemInfo: res
      })
    }
  })
},
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微信小程序提供了 `navigationStyle` 属性来控制小程序导航栏样式。该属性可以在 `app.json` 或页面配置中进行设置。 如果值为 `default`,则表示小程序使用默认的导航栏样式。如果值为 `custom`,则表示小程序使用自定义导航栏样式。 当 `navigationStyle` 的值为 `custom` 时,可以通过以下方式来自定义小程序导航栏样式: 1. 在 `app.json` 中设置全局导航栏背景色和前景色: ```json { "window": { "navigationStyle": "custom", "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black" } } ``` 2. 在页面的 `json` 文件中设置页面导航栏背景色和前景色: ```json { "navigationStyle": "custom", "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black" } ``` 3. 在页面的 `wxml` 文件中添加自定义导航栏: ```html <view class="navbar"> <view class="navbar-back" bindtap="navigateBack"> <image src="/images/icon-back.png"></image> </view> <view class="navbar-title">{{title}}</view> </view> ``` 其中,`navbar` 类指定了导航栏的样式,`navbar-back` 类指定了返回按钮的样式,`navbar-title` 类指定了标题的样式。 4. 在页面的 `wxss` 文件中定义导航栏的样式: ```css .navbar { position: fixed; top: 0; left: 0; width: 100%; height: 44px; background-color: #ffffff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); z-index: 999; } .navbar-back { position: absolute; top: 50%; left: 12px; transform: translate(0, -50%); } .navbar-title { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 18px; font-weight: bold; } ``` 5. 在页面的 `js` 文件中添加返回按钮的逻辑: ```javascript Page({ data: { title: '自定义导航栏' }, navigateBack: function() { wx.navigateBack({ delta: 1 }) } }) ``` 以上就是在微信小程序自定义导航栏的方法,其中 `navigationStyle` 属性用于控制小程序导航栏样式,而自定义导航栏需要在页面中手动添加,并在 `wxss` 文件中进行样式定义。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值