支付宝小程序自定义头部组件

支付宝小程序自定义头部组件

view

<view class="nav-header" style="height:{{navbarData.isFloat?0:statusBarHeight+titleBarHeight}}px">
  <view class="nav-top">
    <image a:if="{{navbarData.isBgImg}}" src="/images/user-bg.png" class="headder-bg" style="width:100%;height:{{statusBarHeight+titleBarHeight}}px;"></image>
    <view class="nav-status-bar" style="height:{{statusBarHeight}}px"></view>
    <view class="nav-title-bar" style="height:{{titleBarHeight}}px">
      <view class="nav-left">
        <slot name="header-left"></slot>
      </view>
      <view class="nav-title-text" style="line-height:{{titleBarHeight}}px;">
        <text>{{navbarData.title}}</text>
      </view>
    </view>
  </view>
</view>

js

const app = getApp()
Component({
  props: {
    navbarData: {}
  },
  data: {
    statusBarHeight: '',
    titleBarHeight: ''
  },
  didMount: function () {
    this.setData({
      statusBarHeight: app.globalData.statusBarHeight,
      titleBarHeight: app.globalData.titleBarHeight
    })
  },
  methods: {

  }

})

css


.nav-header{
  width: 100%;
}
.nav-top{
  width: 100%;
  height: auto;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 99;
  background: transparent;
}
.nav-status-bar{
  width: 100%;
  background: transparent;
}
.nav-title-bar{
  width: 100%;
  position: relative;
  background: transparent;
}
.nav-title-text{
  width: 100%;
  /* font-size: 40rpx; */
  color: white;
  text-align: center;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
}
.nav-title-text text{
  position: relative;
  top: 6rpx;
}
.nav-left{
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
}
.headder-bg{
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1
}

实战:

组件上使用

  <navbar navbar-data="{{nvabarData}}" />
// 引用
    nvabarData: {
      isFloat: true,
      title: '喜刷' //导航栏 中间的标题
    },
    height: '',


 onLoad() {
    // 获取用户数据
    this.setData({
      height: app.globalData.statusBarHeight + app.globalData.titleBarHeight,
    })

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值