官方文檔給的代碼復制下來發現無法滾動,沒反應,使用css設置浮動屬性也無效
官方沒有給出css代碼,橫向需要設置兩個css屬性才行:
white-space: nowrap; ----規定段落中的文本不進行換行
display: inline-block; ----應用此特性的元素呈現為內聯對象,周圍元素保持在同一行,但可以設置寬度和高度地塊元素的屬性
.bc_green {background: green;width:100px; height: 100px;} .bc_red {background: red;width:100px; height: 100px;} .bc_blue {background: blue;width:100px; height: 100px;} .scroll-view_H{ width: 100%; white-space: nowrap; } .scroll-view-item_H{ width: 200px; height: 100px; display: inline-block; }
現在我們只要橫向滾動的代碼出來在加上上面的css就可以橫向滾動啦
<view class="section"> <view class="section__title">horizontal scroll</view> <scroll-view class="scroll-view_H" scroll-x > <view id="green" class="scroll-view-item_H bc_green"></view> <view id="red" class="scroll-view-item_H bc_red"></view> <view id="blue" class="scroll-view-item_H bc_blue"></view> </scroll-view> </view>