当前位置:网站首页>Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
2022-04-23 04:45:00 【Zhou zhouchi】
In a previously completed applet project , Encounter the height of the navigation bar at the top of wechat , There are different problems in different hand heights ( Not suitable for wechat capsule button ). Summed up the idea of sorting out this article
problem
- A front-end , I certainly don't want the page structure to be ugly . Customer 、 Boss 、 I'm not satisfied
resolvent
- adopt
uni.getSystemInfo
Get system information ( Used to the height of mobile phone status bar ), Because the height of the status bar is different, mobile phones are different , The status bar is as follows
- adopt
uni.getMenuButtonBoundingClientRect()
Get the information of wechat applet capsule button (top: The coordinates of the upper boundary of the capsule button 、height: The height of the capsule button ) - adopt
wx.getSystemInfoSync()
holdpx
Turn intorpx
, becauseuni.getSystemInfo
anduni.getMenuButtonBoundingClientRect()
The data units obtained arepx
Key code
uni.getSystemInfo({
success: function(e) {
let myStatusBar = 0
let myCustomBar = 0
let myNvaMartom = 0
let myNavHeight = 0
let custom = uni.getMenuButtonBoundingClientRect();
myStatusBar = e.statusBarHeight;
myNavHeight = custom.height
myNvaMartom = custom.top - e.statusBarHeight
myCustomBar = (myNvaMartom * 2 + custom.height) - 2
that.StatusBar = myStatusBar * 750 / wx.getSystemInfoSync()
.windowWidth;
that.CustomBar = (myCustomBar * 750 / wx.getSystemInfoSync()
.windowWidth)+12;
that.NvaMartom = myNvaMartom * 750 / wx.getSystemInfoSync()
.windowWidth;
that.NavHeight = myNavHeight * 750 / wx.getSystemInfoSync()
.windowWidth;
that.Page_MagTOP = that.CustomBar + that.StatusBar
console.log(" Top status bar height ", that.StatusBar)
console.log(" Navigation bar height ", that.CustomBar)
console.log(" The upper margin of the capsule button ", that.NvaMartom)
console.log(" Capsule button height ", that.NavHeight)
console.log(" The top margin of the page content from the top , Full height of navigation bar ", that.Page_MagTOP)
}
})
The top navigation bar must be used a lot , So it needs to be packaged , Defined as a common component
components/Status_bar/Status_bar.vue
<template>
<view class="">
<view :style="{'height':Page_MagTOP+'rpx'}" style="width: 750rpx;"></view>
<view class="status_bar_my " :style="{'height':StatusBar+'rpx','background-color':Statusbar_top_bgc}">
</view>
<view class="" style="width: 750rpx;position: fixed;z-index: 16000;" :style="{'top':StatusBar+'rpx','height':CustomBar+'rpx'}">
<view class="page_title_ii" style="z-index: 999;" :style="{'height':CustomBar+'rpx','background-color':Statusbar_bgc,'color':color}">
<view class="" style="
width: 50rpx;
" @tap="childMethod()" :style="{
'height':NavHeight+'rpx','line-height':NavHeight+'rpx'}">
<span class="iconfont" v-if='iSTotheArrow' style="font-size: 34rpx;font-weight: 700;" :style="{'color':color}"></span>
</view>
<text class="font-size-tile" :style="{'height':NavHeight+'rpx','line-height':NavHeight+'rpx'}" style="">{
{
HeadLineTitle}}</text>
<view class="navigateBackrr"></view>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
HeadLineTitle: {
type: String,
default: ' Top title '
},
Statusbar_top_bgc: {
type: String,
default: '#fff'
},
Statusbar_bgc: {
type: String,
default: '#fff'
},
color: {
type: String,
default: '#000'
},
fatherMethod: {
type: Function,
default: null
},
iSTotheArrow: {
type: Boolean,
default: true
}
},
data() {
return {
StatusBar: 0,
CustomBar: 0,
NvaMartom: 0,
NavHeight: 0,
Page_MagTOP: 0,
}
},
methods: {
childMethod() {
if (this.fatherMethod) {
this.fatherMethod()
}
}
},
mounted() {
let that = this
uni.getSystemInfo({
success: function(e) {
let myStatusBar = 0
let myCustomBar = 0
let myNvaMartom = 0
let myNavHeight = 0
let custom = uni.getMenuButtonBoundingClientRect();
myStatusBar = e.statusBarHeight;
myNavHeight = custom.height
myNvaMartom = custom.top - e.statusBarHeight
myCustomBar = (myNvaMartom * 2 + custom.height) - 2
that.StatusBar = myStatusBar * 750 / wx.getSystemInfoSync()
.windowWidth;
that.CustomBar = (myCustomBar * 750 / wx.getSystemInfoSync()
.windowWidth)+12;
that.NvaMartom = myNvaMartom * 750 / wx.getSystemInfoSync()
.windowWidth;
that.NavHeight = myNavHeight * 750 / wx.getSystemInfoSync()
.windowWidth;
that.Page_MagTOP = that.CustomBar + that.StatusBar
}
})
this.$emit("ZXNavigtionHeigth",that.Page_MagTOP)
this.$emit("ZXStatusBar",that.StatusBar)
this.$emit("ZXNavHeight",that.NavHeight)
}
}
</script>
<style lang="scss">
.status_bar_my {
position: fixed;
top: 0rpx;
height: var(--status-bar-height);
width: 750rpx;
z-index: 1000;
background-color: #ffffff;
}
=
.page_title_ii {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 36rpx;
z-index: 999;
padding: 0 25rpx;
.navigateBackrr {
width: 50rpx;
height: 50rpx;
}
}
</style>
iSTotheArrow
Method of receiving parent component ,( How to exit the page arrow )
this.$emit()
Trigger the method on the instance , Pass the value of the public component to the parent component
call
- Import re registration
import Status_bar from '@/components/Status_bar/Status_bar.vue'
- Use
<StatusBar HeadLineTitle=' Account settings ' Statusbar_top_bgc='#f63434' Statusbar_bgc='#f63434' color='#fff' :fatherMethod='fatherMethod'></StatusBar>
design sketch
iPhone 5
iPhone XS Max
版权声明
本文为[Zhou zhouchi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220557472717.html
边栏推荐
- Detailed explanation of life cycle component of jetpack
- win10, mysql-8.0.26-winx64. Zip installation
- 数据孤岛是什么?为什么2022年仍然存在数据孤岛?
- Leetcode - > 1 sum of two numbers
- QML advanced (IV) - drawing custom controls
- Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
- 2019 is coming to an end, the longest day.
- Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
- 2021数学建模国赛一等奖经验总结与分享
- zynq平台交叉编译器的安装
猜你喜欢
PIP3 installation requests Library - the most complete pit sorting
Spark small case - RDD, spark SQL
Installation and use of Apache bench (AB pressure test tool)
那些年我面试过的Android开发岗总结(附面试题+答案解析)
test
Summary of MySQL de duplication methods
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
Brushless motor drive scheme based on Infineon MCU GTM module
補:注解(Annotation)
随机推荐
QML advanced (V) - realize all kinds of cool special effects through particle simulation system
Recursive call -- Enumeration of permutations
那些年我面试过的Android开发岗总结(附面试题+答案解析)
La caméra Unity tourne avec la souris
Innovative practice of short video content understanding and generation technology in meituan
Summary of MySQL de duplication methods
Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)
三十六计是什么
IEEE Transactions on systems, man, and Cybernetics: Notes for systems (TSMC)
Supplement: Annotation
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
QML进阶(四)-绘制自定义控件
简单的拖拽物体到物品栏
Leetcode008 -- implement strstr() function
Leetcode - > 1 sum of two numbers
Unity rawimage background seamlessly connected mobile
C language: Advanced pointer
重剑无锋,大巧不工
Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.