欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > 小程序 - - - - - 实现渐隐渐显(监听滚动距离版)

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

2025/8/5 8:13:57 来源:https://blog.csdn.net/Dark_programmer/article/details/140468233  浏览:    关键词:小程序 - - - - - 实现渐隐渐显(监听滚动距离版)

代码如下:

 <!-- 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});}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词