发一篇博客 获取微信小程序胶囊位置

发布时间:2024年01月17日
<script>
export default {
  data() {
    return {
      boxStyle: '', // 盒子样式
    };
  },
  onLoad() {
    // 获取胶囊按钮的位置信息
    const rect = uni.getMenuButtonBoundingClientRect();

    const statusBarHeight = uni.getSystemInfoSync().statusBarHeight; // 获取状态栏高度

    // 计算盒子样式
    this.boxStyle = `top: ${rect.bottom + statusBarHeight}px; right: ${rect.right}px;`;
  },
};
</script>

<style>
.box {
  position: fixed;
  background-color: #ccc;
  width: 200rpx;
  height: 100rpx;
}
</style>

文章来源:https://blog.csdn.net/sdgjah2/article/details/135655639
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。