当前位置: 首页 > news >正文

微信小程序自定义顶部导航栏(适配各种机型)

效果图

1.pages.js,需要自定义导航栏的页面设置"navigationStyle": "custom"

2.App.vue,获取设备高度及胶囊位置

  onLaunch: function () {// 系统信息const systemInfo = uni.getSystemInfoSync()// 胶囊按钮位置信息const menuButtonInfo = uni.getMenuButtonBoundingClientRect()this.globalData.navBarInfo = {statusBarHeight: systemInfo.statusBarHeight,top: menuButtonInfo.top,height: menuButtonInfo.height,paddingTop: menuButtonInfo.top + menuButtonInfo.height + menuButtonInfo.top - systemInfo.statusBarHeight,windowHeight: systemInfo.windowHeight};},

3.在需要的地方设置导航栏高度

<template><view class="customNav" :style="{ ...styleClass, opacity: opacity, backgroundColor: bgcolorString }"><slot></slot></view>
</template>
    const state = reactive({styleClass: {paddingTop: '60px',height: '32px',}})onShow(() => {const navBarInfo = getApp().globalData.navBarInfostate.styleClass = {paddingTop: navBarInfo.statusBarHeight + 'px',height: (navBarInfo.top - navBarInfo.statusBarHeight) * 2 + navBarInfo.height + 'px',}})

http://www.lryc.cn/news/486699.html

相关文章:

  • sslSocketFactory not supported on JDK 9+
  • [Codesys]常用功能块应用分享-BMOV功能块功能介绍及其使用实例说明
  • 大语言模型通用能力排行榜(2024年11月8日更新)
  • 信息技术引领未来:大数据治理的实践与挑战
  • Git 分⽀规范 Git Flow 模型
  • 基于YOLOv8深度学习的公共卫生防护口罩佩戴检测系统(PyQt5界面+数据集+训练代码)
  • Nature Communications 基于触觉手套的深度学习驱动视触觉动态重建方案
  • 构建SSH僵尸网络
  • WPF中MVVM工具包 CommunityToolkit.Mvvm
  • 学习空闲任务函数
  • Hyper-v中ubuntu与windows文件共享
  • 【软件工程】一篇入门UML建模图(类图)
  • Windows 安装Docker For Desktop概要
  • 解决循环依赖报错问题
  • 代码随想录第46期 单调栈
  • 中仕公考怎么样?事业编面试不去有影响吗?
  • OMV7 树莓派 tf卡安装
  • Go语言24小时极速学习教程(五)Go语言中的SpringMVC框架——Gin
  • 【汇编】c++游戏开发
  • Android Studio | 修改镜像地址为阿里云镜像地址,启动App
  • Rocky linux8 安装php8.0
  • Ubuntu 18 EDK2 环境编译
  • C语言项⽬实践-贪吃蛇
  • 智慧安防丨以科技之力,筑起防范人贩的铜墙铁壁
  • Spring:IoC/DI加载properties文件
  • Docker 篇-Docker 详细安装、了解和使用 Docker 核心功能(数据卷、自定义镜像 Dockerfile、网络)
  • 深挖C++赋值
  • 【免越狱】iOS砸壳 可下载AppStore任意版本 旧版本IPA下载
  • 【python笔记02】面向对象思想
  • Java基础-Java多线程机制