欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > uniapp自定义导航头,页面内容自动盛满禁止滚动效果

uniapp自定义导航头,页面内容自动盛满禁止滚动效果

2025/3/22 19:37:52 来源:https://blog.csdn.net/weixin_43857653/article/details/146420993  浏览:    关键词:uniapp自定义导航头,页面内容自动盛满禁止滚动效果

1.pages.jso设置自定义头部 “navigationStyle”: “custom”

{"path" : "pages/a/a","style" : {"navigationBarTitleText" : "自定义头","navigationStyle": "custom"}},

2.效果 源码

<template><view class="container"><view class="custom-navbar" :style="{ height: navBarHeight + 'px' }"><view class="title" :style="{ top: titleTop + 'px', height: titleHeight + 'px' }">123</view></view><view class="content"><text>asasa</text></view></view>
</template>
<script>
export default {data() {return {navBarHeight: 0,  titleTop: 0,  titleHeight: 0 };},onLoad() {this.calculateNavBarHeight();},methods: {calculateNavBarHeight() {const systemInfo = uni.getSystemInfoSync();const menuButtonInfo = uni.getMenuButtonBoundingClientRect();this.navBarHeight = menuButtonInfo.bottom + (menuButtonInfo.top - systemInfo.statusBarHeight);this.titleTop = menuButtonInfo.top;this.titleHeight = menuButtonInfo.height;}}
};
</script>
<style>.container {display: flex;flex-direction: column;height: 100vh;}.custom-navbar {background-color: red;position: relative; }.title {position: absolute;left: 50%;  transform: translateX(-50%); color: white;font-size: 16px;font-weight: bold;display: flex;align-items: center;justify-content: center;}.content {flex: 1;  background-color: green;display: flex;align-items: center;justify-content: center;}
</style>

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词