页面需求:
在滚屏图下方制作一个标签页,对应不同种类的商品,点击对应类别标签滚动到相应商品位置,要求该标签栏一直显示,页面向下滚动时贴顶
制作思路:
1.使用sticky布局制作贴顶标签页
{{item.name}}
样式
.stickyView{
width: 100%;
height: 60rpx;
position: -webkit-sticky;
position: sticky;
background: #f00;
top: 0rpx;
z-index: 100;
}
2.点击标签自动滚动页面到对应位置
navTap(res) {
console.log(res);
let currentTab = res.currentTarget.dataset.index;
this.setData({
currentTab: currentTab
})
let boxHeight = this.data.boxHeight;
console.log(boxHeight);
wx.pageScrollTo({
scrollTop: boxHeight[currentTab],
duration: 0,
success:function(res) {
console.log('success');
console.log(res);
},
fail:function(res) {
console.log("fail");
console.log(res);
}
})
this.scrollLeft();
},
这里出现问题,pageScrollTo无效,经过研究,修改page样式的height为auto或者不设置height,可以让pageScrollTo生效
但是这样设置了之后,position: sticky;就失效了,标签页无法贴顶显示
请问有没有两全的办法可以解决?