W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
可滾動(dòng)視圖區(qū)域。
屬性名 | 類型 | 默認(rèn)值 | 說明 | 最低版本 |
---|---|---|---|---|
scroll-x | Boolean | false | 設(shè)置為橫向滾動(dòng) | 1.0.0 |
scroll-y | Boolean | false | 設(shè)置為豎向滾動(dòng) | 1.0.0 |
upper-threshold | Number | 50 | 距頂部/左邊多遠(yuǎn)時(shí)(單位px),觸發(fā) scrolltoupper 事件 | 1.0.0 |
lower-threshold | Number | 50 | 距底部/右邊多遠(yuǎn)時(shí)(單位px),觸發(fā) scrolltolower 事件 | 1.0.0 |
scroll-top | Number | 設(shè)置豎向滾動(dòng)條位置 | 1.0.0 | |
scroll-left | Number | 設(shè)置橫向滾動(dòng)條位置 | 1.0.0 | |
scroll-into-view | String | 值應(yīng)為某子元素id(id不能以數(shù)字開頭)。設(shè)置哪個(gè)方向可滾動(dòng),則在哪個(gè)方向滾動(dòng)到該元素 | 1.0.0 | |
scroll-with-animation | Boolean | false | 在設(shè)置滾動(dòng)條位置時(shí)使用動(dòng)畫過渡 | 1.0.0 |
bindscroll | EventHandler | 滾動(dòng)時(shí)觸發(fā) | 1.0.0 | |
bindscrolltoupper | EventHandler | 滾動(dòng)到頂部/左邊 | 1.0.0 | |
bindscrolltolower | EventHandler | 滾動(dòng)到底部/右邊 | 1.0.0 |
使用豎向滾動(dòng)時(shí),需要給一個(gè)固定高度,通過 ttss 設(shè)置 height。scroll-into-view只能包含[-_a-zA-Z0-9]
WARNING
不能在scroll-view中使用video、textarea、ad等原生組件 為了保證用戶體驗(yàn),在scroll-view中滾動(dòng)時(shí)不會(huì)觸發(fā)頁面回彈,所以不能觸發(fā)onPullDownRefresh
<view class="page-section-title">
<text>Vertical Scroll\n縱向滾動(dòng)</text>
</view>
<scroll-view style="height: 300rpx;"
scroll-y
scroll-with-animation
bindscrolltoupper="upper"
bindscrolltolower="lower"
bindscroll="scroll"
scroll-into-view="{{toView}}"
scroll-top="{{scrollTop}}"
>
<view id="demo1" class="scroll-view-item demo-text-1"></view>
<view id="demo2" class="scroll-view-item demo-text-2"></view>
<view id="demo3" class="scroll-view-item demo-text-3"></view>
</scroll-view>
<button bindtap="tap">Scroll into</button>
<button bindtap="tapMove">Move</button>
<view class="page-section-title">
<text>Horizontal Scroll\n橫向滾動(dòng)</text>
</view>
<scroll-view class="scroll-view_H" scroll-x style="width: 100%">
<view id="demo1" class="scroll-view-item_H demo-text-1"></view>
<view id="demo2" class="scroll-view-item_H demo-text-2"></view>
<view id="demo3" class="scroll-view-item_H demo-text-3"></view>
</scroll-view>
var order = ['demo1', 'demo2', 'demo3']
Page({
data: {
toView: 'demo1',
scrollTop: 0,
},
upper: function(e) {
console.log(e)
},
lower: function(e) {
console.log(e)
},
scroll: function(e) {
console.log(e)
},
tap: function(e) {
for (var i = 0; i < order.length; ++i) {
if (order[i] === this.data.toView) {
this.setData({
toView: order[i < order.length - 1 ? i + 1 : 0],
})
break
}
}
},
tapMove: function(e) {
this.setData({
scrollTop: this.data.scrollTop + 20
})
}
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: