当前位置:   article > 正文

uni-app自适应顶部导航栏,同时适配微信小程序,h5_uniapp小程序开发顶部导航条背景图片兼容h5

uniapp小程序开发顶部导航条背景图片兼容h5
<template>
	<view class="header-content" >
		<view :style="{height: stateBarHeight + 'px'}"></view>
		<view :style="{height: tabBarHeight + 'px'}" class="header-tabBar">
			<view :style="{height: searchHearch + 'px', width: windowWidth + 'px'}">
				<view class="header-search">
					<Icon 
					type="&#xe62e;" 
					size="20" 
					color="#FFFFFF" 
					class="header-search-icon"></Icon>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stateBarHeight: 0,
				tabBarHeight: 50,
				searchHearch: 30,
				windowWidth: 0,
			};
		},
		created() {
			// 获取设备信息
			this.getStateBarHeight();
			
			
			// 获取小程序右侧悬浮按钮
			// #ifdef MP-WEIXIN
			this.getMenuButtonInfo();
			// #endif
		},
		methods: {
			getStateBarHeight() {
				let info = uni.getSystemInfoSync()
		        this.stateBarHeight = info.statusBarHeight
				this.windowWidth = info.windowWidth
			},
			getMenuButtonInfo() {
				 let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				 
				 let paddingSize = menuButtonInfo.top - this.stateBarHeight
				 this.searchHearch = menuButtonInfo.height
			
						 
				 this.tabBarHeight = 
					 (menuButtonInfo.bottom- this.stateBarHeight) 
					 + paddingSize
					 
				 this.windowWidth = menuButtonInfo.left
			}
		}
	}
</script>

<style lang="scss">
	.header-content {
		background: $uni-color-error;
		.header-tabBar {
			width: 100%;
			display: flex;
			align-items: center;
			.header-search {
				margin: 0 10px;
				border: 1px solid #ffffff;
				border-radius: 30px;
				height: 100%;
				display: flex;
				align-items: center;
				.header-search-icon {
			        flex-shrink: 0;
					margin-left: 10px !important;
				}
			}
		}
		
	}

</style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/103161
推荐阅读
相关标签