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

代码如下:

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
    });
  }
相关推荐
说私域6 小时前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务优化及复购转介绍提升策略研究
人工智能·小程序
熬耶19 小时前
Uniapp之微信小程序自定义底部导航栏形态
微信小程序·小程序·uni-app
IT毕设实战小研1 天前
基于Spring Boot校园二手交易平台系统设计与实现 二手交易系统 交易平台小程序
java·数据库·vue.js·spring boot·后端·小程序·课程设计
weixin_177297220691 天前
剧本杀小程序系统开发:重构推理娱乐生态
小程序·重构·娱乐
IT毕设实战小研2 天前
基于SpringBoot的救援物资管理系统 受灾应急物资管理系统 物资管理小程序
java·开发语言·vue.js·spring boot·小程序·毕业设计·课程设计
程序员陆通3 天前
零基础AI编程开发微信小程序赚流量主广告实战
微信小程序·小程序·ai编程
paopaokaka_luck3 天前
校园快递小程序(腾讯地图API、二维码识别、Echarts图形化分析)
vue.js·spring boot·后端·小程序·uni-app
头发还在的女程序员3 天前
ThinkPHP+Mysql 灵活用工小程序-技术深度解析与实践指南
数据库·mysql·小程序
编程猪猪侠3 天前
解决uni-app微信小程序编译报错:unexpected character `1`
微信小程序·小程序·uni-app
2501_915909063 天前
iOS 签名证书全生命周期实战,从开发到上架的多阶段应用
android·ios·小程序·https·uni-app·iphone·webview