当前位置:网站首页>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
边栏推荐
- 122. The best time to buy and sell stocks II - one-time traversal
- Learning record of uni app dark horse yougou project (Part 2)
- Use of five routing guards
- 读《Software Engineering at Google》(15)
- 41. The first missing positive number
- Abnormal resolution of Xiaomi camera
- 198. Looting - Dynamic Planning
- 386. Dictionary order (medium) - iteration - full arrangement
- Seven cattle upload pictures (foreground JS + background C API get token)
- STM32 entry development board choose wildfire or punctual atom?
猜你喜欢

Allowed latency and side output
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]

Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory

2021长城杯WP

470. 用 Rand7() 实现 Rand10()

Applet learning notes (I)

JS parsing and execution process

470. Rand10() is implemented with rand7()

How to change input into text

QT modification UI does not take effect
随机推荐
On the method of outputting the complete name of typeID from GCC
2022年流动式起重机司机国家题库模拟考试平台操作
[simple understanding of database]
Comparison between xtask and kotlin coroutine
394. 字符串解码-辅助栈
For the space occupation of the software, please refer to the installation directory
Metaprogramming, proxy and reflection
開期貨,開戶雲安全還是相信期貨公司的軟件?
How to sort the numbers with text in Excel from small to large instead of the first number
Using quartz under. Net core - calendar of [6] jobs and triggers
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
vite配置proxy代理解决跨域
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
双指针进阶--leetcode题目--盛最多水的容器
2021 Great Wall Cup WP
C dapper basically uses addition, deletion, modification and query transactions, etc
超分之TDAN
C语言程序设计之函数的构造
198. 打家劫舍-动态规划
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory