微信小程序顶部透明状态标题栏搜索栏与胶囊对齐

微信小程序顶部透明状态标题栏搜索栏LOGO与胶囊对齐

效果如下

App.js

 wx.getSystemInfo({
      success: res => {
        console.log(res)
        let custom = wx.getMenuButtonBoundingClientRect();//菜单按钮
        let systemInfo = wx.getSystemInfoSync();
        this.globalData.custom = custom;
        this.globalData.customBar = custom.height;
        this.globalData.statusBar = custom.top;
        this.globalData.navBarHeight = (custom.top - systemInfo.statusBarHeight) * 2 + custom.height + systemInfo.statusBarHeight;
      }
    })

 index.js

data:{
    statusBar: app.globalData.statusBar,
    customBar: app.globalData.customBar,
    navBarHeight: app.globalData.navBarHeight,
}

index.wxml

<view class="navbar" style="height:{{navBarHeight}}px;">
  <view class="navbar__wrapper" style="margin-top:{{statusBar}}px; height: {{customBar}}px;">
    <view class="search-box">
      <image src="/images/search.png"></image>
      <input class="search-input" name="search" type='text' confirm-type="search" bindinput="bindinput"></input>
    </view>
  </view>
</view>
<view class="content" style="margin-top:{{navBarHeight}}px;"></view>

index.wxss

.navbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  width: 100%;
  background: #e41f19;
  z-index: 10;
}

.navbar__wrapper {
  background: #e41f19;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}


.search-box {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64rpx;
  width: 70%;
  margin: 0 20rpx;
  background: #f7f7f7;
  border-radius: 50rpx;
  box-sizing: border-box;
  font-size: 30rpx;
  color: #bcc0c7;
}

.search-box image {
  position: absolute;
  flex: 0 0 30rpx;
  width: 30rpx;
  height: 30rpx;
  display: block;
  top: 50%;
  transform: translateY(-50%);
  left: 20rpx;
}

.search-input {
  height: 100%;
  display: flex;
  width: 100%;
  align-items: left;
  color: #999;
  font-size: 26rpx;
  height: 64rpx;
  line-height: 64rpx;
  padding-left: 60rpx;
}

.search-box .btn {
  background-color: #f40;
  color: #ffffff;
  width: 100rpx;
  text-align: center;
  height: 64rpx;
  line-height: 64rpx;
  padding: 0 30rpx;
  border-radius: 50rpx;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值