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

代码如下:

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
    });
  }
相关推荐
m0_5873830043 分钟前
折扣卡CPS系统源码的技术架构与实战开发指南
人工智能·小程序·数据挖掘·系统架构·需求分析
2501_915106321 小时前
苹果App Store上架费用及流程全面解析
android·ios·小程序·https·uni-app·iphone·webview
T01156186 小时前
全栈项目实战手记|艺培场馆课时预约小程序全项目开发历程完整复盘总结
运维·服务器·小程序
lhldsg6 小时前
多商户团购系统源码:技术架构选型与二次开发实战指南
java·小程序·架构
2601_949950636 小时前
一套小程序,解决资料整理、在线刷题和错题复盘
人工智能·小程序·刷题·练习·小程序推荐
白远山9 小时前
智慧场馆解决方案小程序系统开发实战与架构设计指南
java·开发语言·小程序·架构
Rooting++1 天前
小程序{{ }}和vue{{ }}语法的区别
前端·vue.js·小程序
博、、1 天前
折扣卡CPS系统源码实战开发指南:从架构设计到落地部署全解析
小程序·需求分析
lhldsg1 天前
折扣卡CPS小程序定制全流程实战指南:从需求分析到上线部署
java·前端·小程序
suliqiang1 天前
【前端技术】 Web 前端技术36年 演进全景图
信息可视化·微信小程序·小程序·前端框架·uni-app·人机交互·xcode