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

代码如下:

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
    });
  }
相关推荐
2501_9160088920 分钟前
全面解析常用Web前端开发工具:编辑器、调试工具、性能分析器与框架
android·前端·ios·小程序·uni-app·编辑器·iphone
mykj155119 小时前
AI旅拍小程序定制开发,解锁文旅变现新赛道
人工智能·小程序
biwenyunnet1 天前
【99做小程序只认餐宝盈】连锁餐饮小程序怎么做:从系统架构、技术选型到表结构与接口设计的完整实践
小程序·系统架构
27669582921 天前
拼多多m端/小程序 encrypt_info
java·小程序·apache·encrypt_info·encrypt_info解密·拼多多小程序·拼多多m端
克里斯蒂亚诺更新1 天前
微信小程序体验版可以获取当前位置但是正式版不可以-办法解决
微信小程序·小程序
资深前端之路1 天前
微信小程序节点最大限制为5000个
微信小程序·小程序
cosinmz1 天前
PDF 发票合并经验分享:月初高效整理发票的实用方法
经验分享·小程序·pdf·pdf转换·pdf发票合并·发票合并打印
2501_916007472 天前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915909062 天前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
2601_956743682 天前
上海小程序开发公司技术选型指南:Serverless架构如何影响交付质量与长期成本
云原生·小程序·架构·serverless·开发经验·上海