首页 > 微信 > 详细

小程序自定义导航栏

时间:2019-06-13 21:10:22      阅读:153      评论:0      收藏:0      [点我收藏+]

本篇为写给自己看

index.wxml

    <view class="status-bar" style="height:{{statusBarHeight}}px"></view>
    <view class=‘nav‘ style="height:{{titleBarHeight}}px">
      <view class=‘navLeft‘>
        <view class=‘iconBox‘ bindtap=‘tapNavigate‘ data-item=‘person‘>
          <image class=‘icon‘ src=‘/images/icon-personSmall.png‘></image>
        </view>
        <view class=‘leftLine‘></view>
        <view class=‘iconBox‘ bindtap=‘tapNavigate‘ data-item=‘message‘>
          <image class=‘icon‘ src=‘/images/icon-msg.png‘></image>
          <view class=‘redMsg‘></view>
        </view>
      </view>
      <view class=‘navMid‘>商户系统</view>
    </view>

  index.wxss

.nav{
  position: relative;
  left: 0;
  width: 90%;
  margin: 0 auto;
  display: flex;
  align-items: center;
}
.navLeft{
  width: 176rpx;
  height: 64rpx;
  background: rgba(0,0,0,0.10);
  border: 1rpx solid rgba(255, 255, 255, 0.205); 
  border-radius: 68rpx;
  position: absolute;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.navMid{ 
  color: white;
  margin: auto;
  font-size: 32rpx;
}

.iconBox{
  height: 200%;
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center; 
  position: relative;
}
.redMsg{
  position: absolute;
  right: 35%;
  top: 35%;
  width: 10rpx;
  height: 10rpx;
  border-radius: 100%;
  background: red;

}
.leftLine{
  height: 55%;
  border-left: 1rpx solid rgba(255, 255, 255, 0.219);
}

.icon{
  width: 32rpx;
  height: 32rpx;
}

js

  onLaunch: function () {
    const vm = this
    // let totalTopHeightSet = {
    //   ‘iPhone‘: 64,
    //   ‘iPhone X‘: 88,
    //   ‘android‘: 68
    // }
    wx.getSystemInfo({
      success: function (res) {
        let totalTopHeight = 68
        if (res.model.indexOf(‘iPhone X‘) !== -1) {
          totalTopHeight = 88
        } else if (res.model.indexOf(‘iPhone‘) !== -1) {
          totalTopHeight = 64
        }
        vm.globalData.statusBarHeight = res.statusBarHeight
        vm.globalData.titleBarHeight = totalTopHeight - res.statusBarHeight
      },
      failure() {
        vm.globalData.statusBarHeight = 0
        vm.globalData.titleBarHeight = 0
      }
    })
  },

 

小程序自定义导航栏

原文:https://www.cnblogs.com/zwyboom/p/11019439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!