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

代码如下:

 <!-- fixed-left -->
<view class="fixed-box" animation="{{animationData}}">
   这里是渐隐渐显的标签
</view>
.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;
}
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
    });
  }

相关推荐

  1. CSS实现现效果

    2024-07-17 17:36:02       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 17:36:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 17:36:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 17:36:02       58 阅读
  4. Python语言-面向对象

    2024-07-17 17:36:02       69 阅读

热门阅读

  1. 中文科技核心论文发表

    2024-07-17 17:36:02       19 阅读
  2. MPS 后端

    2024-07-17 17:36:02       24 阅读
  3. C# ForgettableKnowledge

    2024-07-17 17:36:02       20 阅读
  4. HarmonyOS 如何下载网络图片

    2024-07-17 17:36:02       23 阅读
  5. Postman 接口测试详解

    2024-07-17 17:36:02       19 阅读
  6. Netty Bootstrap/ServerBootstrap

    2024-07-17 17:36:02       24 阅读
  7. 自制迷宫游戏 c++

    2024-07-17 17:36:02       23 阅读