微信小程序自定义导航栏下滑出现上滑隐藏

wxml文件

<!--pages/index/goodsdetails/goodsdetails.wxml-->
<view>
  <view class="indextop {{scrollTop > 10 ? 'navstyl':'unnavstyl'}}">
    <view style="height:{{statusBarHeight}};"></view>
    <view style="height:{{navheight}};padding:6px 0;display: flex;line-height: 32px;">
      <view style="width:80rpx;opacity:1">《</view>
      <view class="xiangqi {{scrollTop > 10 ? 'xiangqi':'unxiangqi'}}">商品详情</view>
      <view style="width:80rpx"></view>
    </view>
  </view>
</view>
<view>
  <image src="../../../img/topimg.png"></image>
  <image src="../../../img/topimg.png"></image>
  <image src="../../../img/topimg.png"></image>
</view>

wxss文件

/* pages/index/goodsdetails/goodsdetails.wxss */
.indextop{
  position: fixed;
  top: 0;
  right: 0;
  width: 750rpx;
  z-index: 9999;
}
.navstyl{
  background: #ffffff;
  transition: all 1.5s;
}
.unnavstyl{
  transition: all 1.5s;
}
.xiangqi{
  transition: all 1.5s;
  opacity: 1;
  text-align: center;
  flex: 1;
}
.unxiangqi{
  transition: all 1.5s;
  opacity: 0;
  text-align: center;
  flex: 1;
}

js文件

Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight:0,
    navheight:0,
    pagetop:0,
    scrollTop:0,
    numop:0
  },
  onLoad: function (options) {
    this.setData({
       状态栏的高度
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight'] + 'px',
       胶囊的高度 也就是自定导航栏的高度
      navheight:wx.getMenuButtonBoundingClientRect()['height'] + 'px',
       状态栏加导航栏的高度 加上下的padding的高度 12
       pagetop:wx.getMenuButtonBoundingClientRect()['height'] + wx.getSystemInfoSync()['statusBarHeight'] + 12 + 'px',
    })
    console.log(this.data.statusBarHeight)
    console.log(this.data.navheight)
    console.log(this.data.pagetop)
  },
  onPageScroll(e) {//页面滚动就会触发
    this.setData({
      scrollTop:e.scrollTop
    })
  },
})

json文件

{
  "navigationStyle": "custom"
}

效果
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值