如圖微信小程序中 scroll-view組件外div加display:flxed后, scroll-view組件滾動失效
github項目地址:https://github.com/fancaixia/wx-scroll-view
解決辦法:
scroll-view寬度為屏幕寬度,
子元素view.cont設(shè)置overflow:auto;內(nèi)容超出屏幕會出滾動條,然后便可以拖動了,
最外層header設(shè)置overflow-y: hidden;隱藏滾動條杖爽,實現(xiàn)了模擬scroll-view的效果
點擊view.green時 設(shè)置元素cur為當(dāng)前點擊view的offsetLeft
<view class="header">
<scroll-view class="scroll-view_H" scroll-x="{{true}}">
<view class="cont">
<view class="list">
<view class="green" wx:for="{{tags}}" wx:key="{{index}}" bindtap='fnclick'>{{item}}</view>
</view>
<view class="cur" style='left:{{left}}px'></view>
</view>
</scroll-view>
</view>
.header{
background: #fff;
position: fixed;
z-index: 200;
top:0;
left: 0;
height: 60rpx;
overflow-y: hidden;
}
.header .cont{
white-space: nowrap;
position: relative;
height: 90rpx;
overflow:auto;
width:750rpx;
}
.header .cont .list view{
width: 120rpx;
display: inline-block;
text-align: center;
font-size: 30rpx;
}
.cur{
position: absolute;
left: 0;
bottom: 30rpx;
width: 70rpx;
height: 6rpx;
background: yellow;
margin-left: 25rpx;
transition: .5s all ease;
}
Page({
data:{
tags:[
"smile",
"smile",
"smile",
"smile",
"smile",
"smile",
"smile",
"smile",
"smile",
"smile",
"smile"
],
left:0,
},
onLoad(){
},
// 導(dǎo)航條鼠標(biāo)跟隨
fnclick(ev){
this.setData({
left:ev.target.offsetLeft
})
},
})