原生小程序---自定义导航栏以及使用van-popup左侧半屏

效果图

就是这样的效果。。。。,复制下面的代码,调试调试就能直接使用

上代码

图一代码

对于的json文件必须要有这个属性 "navigationStyle": "custom",

wxml

xml 复制代码
<image class="indexBg" src="../../image/indexBg.png" mode="" />
<!-- 放入顶部即可 -->
<watermark name=""></watermark>
<view class="navbar" style="height:{{navHeight+5}}px; ">
  <view class="navBody" style="height:{{navHeight+5-statusBarHeight}}px; margin-top: {{statusBarHeight}}px;">
    <image class="navbar_left" style="top:{{navTop}}px;height:{{jnheight-1}}px;width:{{jnwidth-52}}px" src="../../image/indexUser.png" mode="aspectFit" bindtap="openUsers"></image>
    <view class="navbar_title" style="top:{{navTop}}px;">
      <!-- <image src="../../image/login2.png" mode="" /> -->
    自定义的导航栏
    </view>
  </view>
</view>
<!-- wx:if="{{leftPopup}}" -->
<leftPopupPro id="myChild" bindclosePopup="handleClosePopup" />

wxss css自己写也行

css 复制代码
.indexBg {
  width: 100%;
  height: 100%;
  position: fixed;
}

.navbar {
  width: 100%;
  overflow: hidden;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 10;
  flex-shrink: 0;
}
.navBody{
  display: flex;
  align-items: center;
}
.navbar_left {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  position: absolute;
  left: 34rpx;
  z-index: 11;
  line-height: 1;
  overflow: hidden;
  width: 64rpx;
  height: 64rpx;
}

.navBack image {
  width: 60%;
}

.navbar_left view {
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav_line {
  border-left: 1rpx solid #f0f0f0;
}

.navbar_title {
  width: 100%;
  box-sizing: border-box;
  padding-left: 90px;
  padding-right: 140px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  position: absolute;
  left: 0;
  z-index: 10;
  color: #333;
  font-size: 16px;
  font-weight: bold;
  /* text-overflow: ellipsis; */
  overflow: hidden;
  white-space: nowrap;
}

.navbar_title image{
width: 328rpx;
height: 50rpx;
line-height: 50rpx;
}

js代码

javascript 复制代码
var app = getApp()
Page({

  handleClosePopup() {
    // 处理子组件关闭 Popup 弹窗的事件
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      statusBarHeight: app.globalData.statusBarHeight, //状态栏高度
      navHeight: app.globalData.navHeight, //导航栏高度
      navTop: app.globalData.navTop, //胶囊按钮与顶部的距离
      jnheight: app.globalData.jnheight, //胶囊高度
      jnwidth: app.globalData.jnwidth //胶囊宽度
    })
  },
})

图二(封装成弹窗组件)

wxml

xml 复制代码
<!-- 左侧弹出 -->
<van-popup show="true" position="left" closeable custom-style="height: 100%;width: 90%;">
  <view class="navbar" style="height:{{navHeight+5}}px; ">
    <view class="navBody"
    style="height:{{navHeight+5-statusBarHeight}}px; margin-top: {{statusBarHeight}}px;">
      <view class="navbar_left">
        <text class="navbar_leftImg" style="top:{{navTop}}px;height:36rpx;width:18rpx">
         返回
        </image>
      </view>
    </view>
  </view>
  <view class="contentbox" style="height: calc( 100% - {{navHeight+5}}px )">
  </view>
</van-popup>

wxss css自己写也行

css 复制代码
.navbar {
  width: 100%;
  overflow: hidden;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 10;
  flex-shrink: 0;
  background: #fff;
}
.navBody{
  display: flex;
  align-items: center;
  background: #fff;
}
.navbar_left {
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  position: absolute;
  left: 34rpx;
  z-index: 11;
  line-height: 1;
  overflow: hidden;
  width: 106rpx;
  height: 64rpx;
  background: rgba(255,255,255,0.6);
  border-radius: 25px;
  border: 1px solid rgba(151,151,151,0.2);
}
.navbar_leftImg{
width: 18rpx;
height: 34rpx;
opacity: 0.9;
margin: 0 auto;
}
.contentbox{
  position: relative;
  height: 100%;
}

js代码

javascript 复制代码
const app = getApp()
Component({
  lifetimes: {
    attached: function () {
      this.setData({
        statusBarHeight: app.globalData.statusBarHeight, //状态栏高度
        navHeight: app.globalData.navHeight, //导航栏高度
        navTop: app.globalData.navTop, //胶囊按钮与顶部的距离
        jnheight: app.globalData.jnheight, //胶囊高度
        jnwidth: app.globalData.jnwidth, //胶囊宽度
      })
    }
  },
})
相关推荐
toooooop81 天前
微信小程序轮播图高度自适应优化
微信小程序·小程序
StarChainTech1 天前
电动车租赁行业的核心需求:智能中控设备的选择与技术方案
物联网·微信小程序·小程序·软件需求·共享经济
计算机毕设指导61 天前
基于微信小程序的积分制零食自选平台【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
云起SAAS1 天前
老年美文文章图文短视频资讯阅读抖音快手微信小程序看广告流量主开源
微信小程序·小程序·ai编程·看广告变现轻·老年美文文章图文短视频资讯阅读
qq_12498707531 天前
基于微信小程序的民宿预订系统的设计与实现(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·毕业设计
一室易安1 天前
uniapp+vue3 微信小程序中 页面切换tab 页面滚动到指定锚点位置,滚动页面时候到达指定锚点位置吸顶tab 会自动进行切换
微信小程序·uni-app·notepad++
不想吃菠萝1 天前
pc端微信小程序post传递data是字符串,自动加了双引号问题修改方案
微信小程序·小程序
宠友信息1 天前
打造可持续增长的垂直社区:仿小红书平台功能体系与架构深度解析
java·微服务·微信小程序·springboot·uniapp
一点晖光2 天前
微信小程序输入框光标从中间删除跳到最后bug解决
微信小程序·uniapp·ios光标
小皮虾2 天前
护航隐私!小程序纯前端“证件加水印”:OffscreenCanvas 全屏平铺实战
前端·javascript·微信小程序