当前位置:网站首页>Uniapp custom search box adaptation applet alignment capsule
Uniapp custom search box adaptation applet alignment capsule
2022-04-23 17:43:00 【Front Thoughts】
demand :uniapp Framework development Customize the search bar, compile the wechat applet and align it with the capsule bag on the right !
<template>
<view class="navbar">
<view class="navbar-fixed">
<!-- Status bar applet support height -->
<view :style="{height:statusBarHeight+'px'}"></view>
<view class="navbar-content" :style="{height:navBarHeight+'px',width:windowWidth+'px'}">
<view class="navbar-search">
<view class="navbar-search_icon">
<uni-icons type="search" size="16" color="#999"></uni-icons>
</view>
<view class="navbar-serach">
<input class="navbar-search_text" type="text" v-model="val" placeholder=" Search for good things you want " />
</view>
</view>
</view>
</view>
<!-- Need to add placeholder height Status bar height + Navigation bar height ( Otherwise, below tab Will collapse )-->
<view :style="{height: statusBarHeight+navBarHeight+'px'}"></view>
</view>
</template>
<script>
export default {
name: 'navbar',
data() {
return {
statusBarHeight: 20,/* Status bar height */
navBarHeight: 45,/* Navigation bar height */
windowWidth: 375,/* Window width */
/* Set the default height of the status bar */
val: ''/* The value of the navigation bar search box */
};
},
created() {
// Get mobile system information
const info = uni.getSystemInfoSync()
// Set the height of the status bar (H5 There is no status bar at the top. The applet has a status bar that needs to be raised )
this.statusBarHeight = info.statusBarHeight
this.windowWidth = info.windowWidth
// except h5 app mp-alipay In case of execution
// #ifndef H5 || APP-PLUS || MP-ALIPAY
// Get the location of the capsule
const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
console.log(menuButtonInfo);
// ( Capsule bottom height - The height of the status bar ) + ( Capsule top height - Height in the status bar ) = The height of the navigation bar
this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info.statusBarHeight)
this.windowWidth = menuButtonInfo.left
// #endif
}
}
</script>
<style lang="less">
@import './../../uni.less';
.navbar {
.navbar-fixed {
position: fixed;
top: 0;
left: 0;
z-index: 99;
width: 100%;
background-color: @mk-base-color;
.navbar-content {
display: flex;
justify-content: center;
align-items: center;
padding: 0 15px;
height: 45px;
box-sizing: border-box;
.navbar-search {
display: flex;
align-items: center;
padding: 0 10px;
width: 100%;
height: 30px;
border-radius: 30px;
background-color: #fff;
.navbar-search_icon {
// width: 10px;
// height: 10px;
margin-right: 10px;
}
.navbar-search_text {
width: 100%;
font-size: 14px;
color: #999;
}
}
&.search {
padding-left: 0;
.navbar-content__search-icons {
margin-left: 10px;
margin-right: 10px;
}
.navbar-search {
border-radius: 5px;
}
}
}
}
}
</style>
版权声明
本文为[Front Thoughts]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551156889.html
边栏推荐
- EasymodbusTCP之clientexample解析
- Why do some people say SCM is simple and I have to learn it so hard?
- How to sort the numbers with text in Excel from small to large instead of the first number
- Sword finger offer 03 Duplicate number in array
- 剑指 Offer 03. 数组中重复的数字
- Webapi + form form upload file
- Open futures, open an account, cloud security or trust the software of futures companies?
- Leak detection and vacancy filling (VIII)
- Type judgment in [untitled] JS
- JVM类加载机制
猜你喜欢
干货 | 快速抽取缩略图是怎么练成的?
92. 反转链表 II-字节跳动高频题
Future usage details
In embedded system, must the program code in flash be moved to ram to run?
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
MySQL installation
Halo 开源项目学习(二):实体类与数据表
Leak detection and vacancy filling (6)
Qt 修改UI没有生效
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
随机推荐
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
[batch change MySQL table and corresponding codes of fields in the table]
干货 | 快速抽取缩略图是怎么练成的?
On the method of outputting the complete name of typeID from GCC
In ancient Egypt and Greece, what base system was used in mathematics
Ouvrir des contrats à terme, ouvrir des comptes en nuage ou faire confiance aux logiciels des sociétés à terme?
Metaprogramming, proxy and reflection
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
01-初识sketch-sketch优势
Node template engine (EJS, art template)
MySQL advanced index [classification, performance analysis, use, design principles]
If you start from zero according to the frame
tidb-server 的配置文件在哪里?
01 - get to know the advantages of sketch sketch
XTask与Kotlin Coroutine的使用对比
Applet learning notes (I)
Read software engineering at Google (15)
关于gcc输出typeid完整名的方法
flink 学习(十二)Allowed Lateness和 Side Output
读《Software Engineering at Google》(15)