小程序 - - - - - 实现渐隐渐显(监听滚动距离版)

代码如下:

html 复制代码
 <!-- fixed-left -->
<view class="fixed-box" animation="{{animationData}}">
   这里是渐隐渐显的标签
</view>
css 复制代码
.fixed-box {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #ccc;
  /* background-color: #f9f9f9; */
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  padding: 0rpx 30rpx;
  padding-top: 8rpx;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  opacity: 0;
}
js 复制代码
data:{
    animationData: {},
    fixedShow: false,
},

 /**
  * Monitor the scrolling distance and display animation
  * @param {*} event 
  */
  onPageScroll(event) {
    const scrollTop = event.scrollTop;
    if (scrollTop < 440 && this.data.fixedShow) {
      this.fadeOut();
    } else if (scrollTop >= 440 && !this.data.fixedShow) {
      this.fadeIn();
    }
  },
  fadeIn: function () {
    const animation = this.animation;
    animation.opacity(1).step();
    this.setData({
      animationData: animation.export(),
      fixedShow: true
    });
  },

  fadeOut: function () {
    const animation = this.animation;
    animation.opacity(0).step();
    this.setData({
      animationData: animation.export(),
      fixedShow: false
    });
  }
相关推荐
Nueuis4 小时前
微信小程序前端面经
前端·微信小程序·小程序
轩11510 小时前
实现仿中国婚博会微信小程序
微信小程序·小程序
2501_9189410517 小时前
旅游微信小程序制作指南
微信小程序·小程序·旅游
全职计算机毕业设计18 小时前
SpringBoot+Mysql实现的停车场收费小程序系统+文档
spring boot·mysql·小程序
KerwinChou_CN1 天前
自由开发者计划 004:创建一个苹果手机长截屏小程序
图像处理·算法·智能手机·小程序
Uyker1 天前
空间利用率提升90%!小程序侧边导航设计与高级交互实现
前端·微信小程序·小程序
说私域1 天前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的生态农庄留存运营策略研究
人工智能·小程序·开源·零售
Nightne1 天前
小程序引入deepseek
小程序
胡斌附体1 天前
uniapp路由跳转toolbar页面
小程序·uni-app·switch·路由·type·uview-ui
小二·2 天前
Vue前端篇——Vue 3的watch深度解析
微信小程序·小程序