uniapp导航栏随页面滚动淡出显示隐藏效果

<template>
  <view :style="{ height: statusBarHeight }"></view>
  <view class="demo">
    <navbar title="个人中心" :autoBack="true" :safeAreaInsetTop="true" :style="{ opacity: op }"> </navbar>
    <view style="height: 150vh">213</view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import { onLoad, onPageScroll } from "@dcloudio/uni-app";
import navbar from "@/uni_modules/uview-plus/components/u-navbar/u-navbar.vue";

const statusBarHeight = ref(0);
const navHeight = ref(0);
const op = ref(0);

onLoad(() => {
  uni.getSystemInfo({
    success: (res) => {
      // 根据设备屏幕大小设置状态栏高度
      if (res.platform === "android") {
        statusBarHeight.value = res.statusBarHeight + "rpx";
        navHeight.value = 88;
      } else if (res.platform === "ios") {
        statusBarHeight.value = res.statusBarHeight + "rpx";
        navHeight.value = 108;
      }
    },
  });
});
onPageScroll((res) => {
  let top = res.scrollTop;
  let height = navHeight.value;
  console.log(height);
  if (top <= height) {
    op.value = Math.round((top / height) * 100) / 100;
  } else {
    op.value = 1;
  }
});
</script>

<style scoped>
.demo {
  width: 100%;
  overflow: hidden;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值