您现在的位置是:网站首页> 编程资料编程资料

微信小程序实现吸顶盒效果_javascript技巧_

2023-05-24 338人已围观

简介 微信小程序实现吸顶盒效果_javascript技巧_

本文实例为大家分享了微信小程序实现吸顶盒效果的具体代码,供大家参考,具体内容如下

html部分

                                    合伙人                              操作                                                                                      {{item.agent_name}}                                                                            成员管理                         设备管理                         门店管理                                                                                                      补货申请                         补货申请记录                                                            

css部分 

.partner-content-container{     width: 100%;     background: #fff; } .partner-list-header{     display: flex;     justify-content: space-around;     height: 80rpx;     line-height: 80rpx;     border-bottom: 3rpx dashed #b2b3b2;     margin: 0 20rpx;     font-weight:bold;     background: #fff;     width: 100%; } .tab-fixed{     position: fixed;     top: 0;     left: 0;     z-index: 1; } .partner-list-title{     width: 40%;     text-align: center; } .icon-container{     display: flex;     justify-content:center;     align-items: center; } .right-arrow{     width: 50rpx;     margin-right: 20rpx; } .partner-list-content{     display: flex;     justify-content: space-around;     align-items: center;     background: #fff;     line-height: 100rpx;     margin: 0 20rpx; } .co-wrapper{     width: 55%;     box-sizing: border-box; } .item-desc{     width:45%;     overflow: hidden;     white-space: nowrap;     text-overflow: ellipsis;     text-align: center; } .co-btn{     background: rgb(14 37 199);     font-size: 24rpx;     margin-top: 10rpx;       border-radius: 10rpx;     color: #fff;     padding: 18rpx 22rpx;     margin:0 10rpx 0 0; }

js部分

data:{    navbarInitTop: 0, //导航栏初始化距顶部的距离   isFixedTop: false, //是否固定顶部 } /*监听页面滑动事件*/     onPageScroll: function(e) {        let that = this;        let scrollTop = parseInt(e.scrollTop); //滚动条距离顶部高度        let isSatisfy = scrollTop >= that.data.navbarInitTop ? true : false;        //为了防止不停的setData, 这儿做了一个等式判断。 只有处于吸顶的临界值才会不相等       if (that.data.isFixedTop === isSatisfy) {         return false;       }        that.setData({            isFixedTop:isSatisfy        })     },     onShow: function () {         let that = this;         wx.createSelectorQuery().select('#operation-bar').boundingClientRect(function(rect) {             if (rect && rect.top > 0) {                 var navbarInitTop = parseInt(rect.top);                 that.setData({                     navbarInitTop: navbarInitTop                 });                  console.log(that.data.navbarInitTop)             }         }).exec();     },

wx.createSelectorQuery().select('#operation-bar').boundingClientRect(function(rect)}rect值可能为null

有查询节点需求可以用延时方法或者操作事件来获取。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

-六神源码网