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

代码如下:

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
    });
  }
相关推荐
蓝黑202011 小时前
从经纬度获取地理信息以及从地名获取经纬度
小程序
吴声子夜歌20 小时前
小程序——逻辑层
小程序
花木偶20 小时前
小迪网安:APP攻防-Day1
安全·小程序
吴声子夜歌2 天前
小程序——生命周期函数和事件处理函数
服务器·前端·小程序
hnxaoli2 天前
win10程序(十六)通达信参数清洗器
开发语言·python·小程序·股票·炒股
吴声子夜歌3 天前
小程序——项目结构
小程序
Lucky小黄人4 天前
微信小程序查看备案号
微信小程序·小程序
毕设源码-郭学长4 天前
【开题答辩全过程】以 基于微信小程序的当当手办店铺为例,包含答辩的问题和答案
微信小程序·小程序
qq_24218863324 天前
微信小程序新年首页源码
微信小程序·小程序
中国胖子风清扬5 天前
GPUI 在 macOS 上编译问题排查指南
spring boot·后端·macos·小程序·rust·uni-app·web app