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

代码如下:

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
    });
  }
相关推荐
被制作时长两年半的个人练习生3 小时前
【微信小程序】小程序开发思想之异步与渲染
微信小程序·小程序
V+zmm1013420 小时前
ssm基于微信小程序的食堂窗口自助点餐系统源码调试讲解
微信小程序·小程序
笃励1 天前
小程序面试题一
小程序
hmz3601 天前
2024升级zblog小程序开源源码/基于uniapp开发的(支持微信小程序、百度小程序、安卓APP)
微信小程序·小程序·uni-app
码农NoError1 天前
react state 状态数据
微信小程序·小程序
结衣结衣.1 天前
通过小程序进度条了解Linux下的多文件操作
linux·运维·服务器·c语言·开发语言·c++·小程序
启山智软1 天前
【对商城小程序命名的一些建议】
java·小程序
源码指南1231 天前
基于SSM+小程序的乡村游小程序登录管理系统(旅游3)(源码+sql脚本+视频导入教程+文档)
小程序·旅游
源码指南1231 天前
基于SSM+小程序的智慧旅游平台登录管理系统(旅游2)(源码+sql脚本+视频导入教程+文档)
小程序·旅游
YesPMP官方账号1 天前
如何满足业主多元需求?开发物业APP,打造智能社区生活
大数据·小程序·app·软件开发·物业