`
hereson
  • 浏览: 1427762 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

微信小程序--搜索框滚动到顶部时悬浮

阅读更多
<scroll-view style="width:100%;height: 100%;" scroll-y="true" bindscroll="scrollTopFun">
    <view class="{{top>130 ? 'topnav' : ''}}">
    <--这里写大于130,表示距离顶部130rpx时固定,可根据需要修改-->
        ...
    </view>
</scroll-view>

 wxss

.topnav{
    position: fixed;
    top: 85rpx;
    z-index:99;
    background: #fff;
    width: 100%;
}

 js

data = {
  top:0
}
//控制回到顶部按钮的显示与消失
scrollTopFun(e){
    let that = this;
    that.top = e.detail.scrollTop;
    that.$apply();
}

 

或者

onPageScroll:function(e){
		let that = this;
		that.setData({top: e.scrollTop });
},

 当页面滚动时导航条到达搜索栏下方时固定,向上滚动到导航条位置时又恢复原样。 

 参考:askjava

分享到:
评论
1 楼 GGGGeek 2019-05-18  
第一个函数滚动监听不起作用,onPageScroll可以

相关推荐

Global site tag (gtag.js) - Google Analytics