uniapp -- 自定義頭部導航


  

步驟一:

app.json:中添加:

"window": {
    "navigationStyle":"custom"
  }

步驟二:

app.js:獲取手機系統信息及導航高度:

App({
  onLaunch: function (options) {
    // 獲取手機系統信息
    wx.getSystemInfo({
      success: res => {
        //導航高度
        this.globalData.navHeight = res.statusBarHeight + 46;
      }, fail(err) {
        console.log(err);
      }
    })
  },
  globalData: {
    navHeight: 0
  }
})

步驟三:

app.wxss:導航樣式:

.nav {
  width: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  background: #fff;
}
 
.title_text {
  width: 100%;
  height: 45px;
  line-height: 45px;
  text-align: center;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 10;
  font-size: 34rpx;
}
 
.title_icon {
  position: absolute;
  bottom: 10rpx;
  left: 10rpx;
  border-radius: 70rpx;
  box-sizing: border-box;
  border: 0.5px solid #eaeaea;
  display: flex;
  z-index: 20;
}
 
.title_icon image {
  display: inline-block;
  overflow: hidden;
  width: 32rpx;
  height: 36rpx;
  padding: 16rpx 32rpx;
  text-align: center;
}
 
.title_icon view {
  height: 18px;
  border-left: 1px solid #eaeaea;
  margin-top: 6px;
}

步驟四:pages中的頁面加入導航index.wxml

<view class='nav' style='height:{{navH}}px'>
  <view class='title_icon'>
    <image src='back.png' mode='aspectFit' class='back' bindtap='navBack'></image>
 
    <view></view>
    <image src='home.png' mode='aspectFit' class='home' bindtap='navHome'></image>
  </view>
  <view class='title_text'>
    BPHOTO
  </view>
</view>
<!--正文-->
<view class="container" style="margin-top: {{navH}}px">
 
 
</view>

步驟五:pages的頁面index.js

const app = getApp()
Page({
  onLoad: function(options) {
    // swiper設置高度
    var that = this;
    that.setData({
      navH: app.globalData.navHeight
    })
   },
  // 返回上一頁
  navBack: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  navHome: function () {
    wx.reLaunch({
      url: '../index/index'
    })
  }
})


原文鏈接:https://blog.csdn.net/u012054869/article/details/88304557


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM