您的位置:首页 > 文旅 > 旅游 > uniapp小程序获取右上角胶囊位置信息

uniapp小程序获取右上角胶囊位置信息

2025/2/25 1:15:09 来源:https://blog.csdn.net/weixin_48998573/article/details/139831515  浏览:    关键词:uniapp小程序获取右上角胶囊位置信息

在这里插入图片描述

文章目录

  • 导文
  • 使用uni.getMenuButtonBoundingClientRect();方法实现
      • 完整案例
  • 隐藏默认导航栏:
    • 全局隐藏
    • 当前页面隐藏


导文

uniapp小程序获取右上角胶囊位置信息

使用uni.getMenuButtonBoundingClientRect();方法实现

<script>const menuButtonInfo = uni.getMenuButtonBoundingClientRect();export default {data() {return {menuButtonInfo: menuButtonInfo, //右侧胶囊详细信息}},onLoad() {// this.menuButtonInfo = uni.getMenuButtonBoundingClientRect();// console.log('onLoad',uni.getMenuButtonBoundingClientRect());},onReady() {console.log('onReady');console.log('onReady',uni.getMenuButtonBoundingClientRect());},methods: {}}
</script>

在这里插入图片描述

完整案例

在这里插入图片描述

<template><view class="checkIn"><view class="checkIn-date" :style="{ padding: capsulePadding() }"><view class="checkIn-nav" :style="{ height: capsuleHeight() }"><uni-icons type="plus-filled" size="30" color="#ffffff"></uni-icons></view><view class="checkIn-data-main"></view></view><view class="checkIn-main"><uni-card title="标题文字" thumbnail="" extra="额外信息" note="Tips">内容主体,可自定义内容及样式</uni-card></view></view>
</template><script>export default {components: {},data() {return {}},onLoad() {},onReady() {console.log('onReady');},methods: {// 获取胶囊高度capsuleHeight() {if (uni?.getMenuButtonBoundingClientRect()) {return `${uni.getMenuButtonBoundingClientRect().height + uni.getMenuButtonBoundingClientRect().top * 2}px`;} else {return `100px`;}},// 获取侧边宽度capsulePadding() {if (uni?.getMenuButtonBoundingClientRect()) {const res = uni.getSystemInfoSync().windowWidth;return `0px ${res - uni.getMenuButtonBoundingClientRect().right}px`;} else {return `10px`;}}}
}
</script><style lang="scss">
.checkIn {.checkIn-date {width: 100%;height: 200px;background-image: url('../../static/checkIn/top-back.png');}.checkIn-nav {width: 100%;height: 148px;display: flex;align-items: center;}
}
</style>

隐藏默认导航栏:

全局隐藏

在你的页面 pages.json 配置中,为相应的页面设置 navigationStylecustom,这将隐藏默认的导航栏。

  	"globalStyle": {"navigationStyle": "custom"},

当前页面隐藏

   {"pages": [{"path": "pages/index/index","style": {"navigationStyle": "custom"}},// ... 其他页面配置]}

您好,我是肥晨。
欢迎关注我获取前端学习资源,日常分享技术变革,生存法则;行业内幕,洞察先机。

版权声明:

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

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