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

代码如下:

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
    });
  }
相关推荐
難釋懷8 小时前
微信小程序全局配置
微信小程序·小程序
Enti7c8 小时前
微信小程序核心知识点速览
微信小程序·小程序
2501_9159184121 小时前
Fiddler中文版全面评测:功能亮点、使用场景与中文网资源整合指南
android·ios·小程序·https·uni-app·iphone·webview
说私域1 天前
从品牌附庸到自我表达:定制开发开源AI智能名片S2B2C商城小程序赋能下的营销变革
人工智能·小程序
難釋懷1 天前
第一个小程序
小程序
春哥的研究所1 天前
可视化DIY小程序工具!开源拖拽式源码系统,自由搭建,完整的源代码包分享
小程序·开源·开源拖拽式源码系统·开源拖拽式源码·开源拖拽式系统
weixin_lynhgworld1 天前
盲盒一番赏小程序技术实现方案:高并发与防作弊的平衡之道
小程序
今日热点1 天前
小程序主体变更全攻略:流程、资料与异常处理方案
经验分享·微信·小程序·企业微信·微信公众平台·微信开放平台
鸭鸭梨吖1 天前
微信小程序---下拉框
微信小程序·小程序
mon_star°1 天前
搭建一款结合传统黄历功能的日历小程序
微信·微信小程序·小程序·微信公众平台