当前位置:网站首页>Applet custom top navigation bar, uni app wechat applet custom top navigation bar
Applet custom top navigation bar, uni app wechat applet custom top navigation bar
2022-07-01 02:23:00 【The bald road of procedural ape】
A demand requires the button in the upper left corner , Change to Icon , The effect is as follows

1、 To customize the top navigation bar, you need to pay attention to , For details, please refer to uniapp file , To view the document

2、 Detailed code and configuration , The key point is to be compatible with different models
2.1 page.json Remove the native navigation bar style from the file "navigationStyle": "custom"

2.2 App.vue stay onShow Get data from and store
<script>
export default {
onShow: function() {
console.log('App Show')
uni.getSystemInfo({
success: (result) => {
// Get the height of the status bar of the mobile phone system ( Different mobile phones have different status bar heights ) ( Do not use uni-app Official document var(--status-bar-height) Officially, this is fixed 20px It's not right )
// console.log(' Current mobile phone status bar height ',result.statusBarHeight)
let statusBarHeight = result.statusBarHeight + 'px'
// Get information about the right capsule Company px
const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
//bottom: The distance from the bottom of the capsule to the top of the screen
//height: Capsule height
//left: The distance from the left side of the capsule to the left side of the screen
//right: The distance from the right side of the capsule to the left side of the screen
//top: The distance from the top of the capsule to the top of the screen
//width: Capsule width
// console.log(menuButtonInfo.width, menuButtonInfo.height, menuButtonInfo.top)
// console.log(' Calculate the distance from the right side of the capsule to the right side of the screen ', result.screenWidth - menuButtonInfo.right)
let menuWidth = menuButtonInfo.width + 'px'
let menuHeight = menuButtonInfo.height + 'px'
let menuBorderRadius = menuButtonInfo.height / 2 + 'px'
let menuRight = result.screenWidth - menuButtonInfo.right + 'px'
let menuTop = menuButtonInfo.top + 'px'
let contentTop = result.statusBarHeight + 44 + 'px'
let menuInfo = {
statusBarHeight: statusBarHeight,// Status bar height ---- Used to design the top navigation bar of the custom navigation bar page padding-top Use : Purpose to set aside the status bar area of the system
menuWidth: menuWidth,// Capsule width on the right -- It is used to set the left capsule of the customized navigation bar page
menuHeight: menuHeight,// Capsule height on the right -- It is used to set the left capsule of the customized navigation bar page
menuBorderRadius: menuBorderRadius,// Half fillet -- It is used to set the left capsule of the customized navigation bar page
menuRight: menuRight,// The distance between the capsule on the right and the screen on the right -- It is used to set the left capsule of the customized navigation bar page
menuTop: menuTop,// The distance from the top of the capsule on the right to the top of the screen -- It is used to set the left capsule of the customized navigation bar page
contentTop: contentTop,// The height of the content area from the top of the page -- It is used to locate the distance of the content area of the custom navigation bar page
}
uni.setStorageSync('menuInfo', menuInfo)
},
fail: (error) => {
console.log(error)
}
})
},
}
</script>2.3 Customize the top navigation bar page
<template>
<view class="index-page">
<!-- paddingTop If it does not take effect, it can be replaced by marginTop -->
<view class="tab_title" :style="{ paddingTop: statusBarHeight}">
<!-- Custom style in the upper left corner -->
<view class="menu_btn flex-betwee box-sizing"
:style="{ position: 'fixed', top: menuTop, left: menuRight, width: menuWidth, height: menuHeight, borderRadius: menuBorderRadius}">
<image class="logo" src="/static/logo.png" @click="goStepPage"></image>
<view class="tit">uniapp</view>
</view>
</view>
<view class="content_box box-sizing" :style="{marginTop:contentTop}">
Content
</view>
</view>
</template>
<script>
export default {
data() {
return {
statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,// The height of the status bar ( Can be set as the top navigation bar padding-top)
menuWidth: uni.getStorageSync('menuInfo').menuWidth,
menuHeight: uni.getStorageSync('menuInfo').menuHeight,
menuBorderRadius: uni.getStorageSync('menuInfo').menuBorderRadius,
menuRight: uni.getStorageSync('menuInfo').menuRight,
menuTop: uni.getStorageSync('menuInfo').menuTop,
contentTop: uni.getStorageSync('menuInfo').contentTop,
}
},
}
</script>
<style lang="scss" scoped>
.box-sizing {
box-sizing: border-box;
}
.index-page {
width: 100vw;
height: calc(100vh - 64px); // Solve the problem of scrolling up and down when the page has no content Height default 44px + padding-top 20px
// padding: 32rpx;
.tab_title {
width: 100%;
height: 44px !important; // This is fixed 44px( The top height of all applets is = 44px + Height of mobile phone system status bar )
line-height: 44px;
text-align: center;
// background-color: #d00;
background-color: #f8f8f8 !important;
position: fixed;
top: 0;
z-index: 9999;
color: #000;
font-weight: 500;
.menu_btn {
width: 414rpx !important;
// background-color: #ffffff; // This is the default title bar background color of the applet
overflow: hidden;
// position: fixed; // Fixed positioning is written in the inline -- The purpose is to remove the problem of scrolling down the page together
.arrowleft {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-160%, -50%) !important;
-webkit-transform: translate(-160%, -50%) !important;
}
.text_box {
width: 1rpx;
height: 20px;
background-color: #ddd;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
-webkit-transform: translate(-50%, -50%) !important;
}
.home {
position: absolute;
top: 50%;
left: 50%;
transform: translate(60%, -50%) !important;
-webkit-transform: translate(60%, -50%) !important;
}
}
}
}
</style>complete , The code can be copied directly
边栏推荐
- 機器學習10-信念貝葉斯分類器
- I want to know how to open a stock account? Is it safe to open an account online?
- 开源基础软件公司,寻找一起创造未来的你(API7.ai)
- 聚焦绿色低碳,数据中心散热进入“智能冷却”新时代
- AS400 大廠面試
- C # generates PPK files in putty format (supports passphrase)
- 手机edge浏览器无法打开三方应用
- halcon数组的一些使用
- Open source basic software companies, looking for you to create the future together (api7.ai)
- 2022年最新csdn涨薪技术栈-app自动化测试概述
猜你喜欢

修复表中的名字(首字符大写,其他小写)
![Pytorch - - Basic Reference North Deux élèves du secondaire peuvent comprendre [Rétropropagation et Gradient descendant]](/img/6e/279dbb7a8d7a5ecd240de464c5b8b2.png)
Pytorch - - Basic Reference North Deux élèves du secondaire peuvent comprendre [Rétropropagation et Gradient descendant]

视觉特效,图片转成漫画功能

FL Studio20.9水果软件高级中文版电音编曲

Rocketqa: cross batch negatives, de noised hard negative sampling and data augmentation

CorelDRAW 2022 Chinese Simplified 64 bit direct download

我的PMP学习考试心得

Pycharm 打开远程目录 Remote Host

Batch import of Excel data in applet
The latest CSDN salary increase technology stack in 2022 overview of APP automated testing
随机推荐
SWT/ANR问题--StorageManagerService卡住
AS400 large factory interview
How does the property send a text message to the owner?
PMP是什么?
URL和URI
RocketQA:通过跨批次负采样(cross-batch negatives)、去噪的强负例采样(denoised hard negative sampling)与数据增强(data augment
Zero foundation self-study SQL course | window function
import tensorflow.contrib.slim as slim报错
How do the top ten securities firms open accounts? Also, is it safe to open an account online?
手机上怎么开户?还有,在线开户安全么?
Alphabet-Rearrange-Inator 3000(字典树自定义排序)
Desai wisdom number - other charts (parallel coordinate chart): employment of fresh majors in 2021
Pytorch —— 基礎指北_貳 高中生都能看懂的[反向傳播和梯度下降]
Ernie-gram, 显式、完备的 n-gram 掩码语言模型,实现了显式的 n-gram 语义单元知识建模。
详解数据治理知识体系
C#生成putty格式的ppk文件(支持passphrase)
Windows quick add boot entry
Do you write API documents or code first?
Template: globally balanced binary tree
LabVIEW计算相机图像传感器分辨率以及镜头焦距