index.axml
<view class="{{class}}" hidden="{{isShow}}"> <input class="examSearch" onInput="examSearch" onSubmit="examSearch" type="text" placeholder="考试搜索"/> </view>
index.js
Page({ data:{ class:'', }, // 滚动定位 onPageScroll({ scrollTop }) { this.setData({ scrollTop: scrollTop }); if (scrollTop >= 45){ this.setData({ class:"fixed" }) } else { this.setData({ class:"" }) } }, })
index.acss
.fixed{ position: fixed; top: 0; left: 0; right: 0; z-index: 999; background-color: white; border-bottom: 2rpx solid #ddd; }