您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“微信小程序中scroll-view怎么用”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信小程序中scroll-view怎么用”這篇文章吧。
可滾動視圖區(qū)域。
屬性名 | 類型 | 默認(rèn)值 | 說明 |
---|---|---|---|
scroll-x | Boolean | false | 允許橫向滾動 |
scroll-y | Boolean | false | 允許縱向滾動 |
upper-threshold | Number | 50 | 距頂部/左邊多遠(yuǎn)時(shí)(單位px),觸發(fā) scrolltoupper 事件 |
lower-threshold | Number | 50 | 距底部/右邊多遠(yuǎn)時(shí)(單位px),觸發(fā) scrolltolower 事件 |
scroll-top | Number | 設(shè)置豎向滾動條位置 | |
scroll-left | Number | 設(shè)置橫向滾動條位置 | |
scroll-into-view | String | 值應(yīng)為某子元素id(id不能以數(shù)字開頭)。設(shè)置哪個方向可滾動,則在哪個方向滾動到該元素 | |
scroll-with-animation | Boolean | false | 在設(shè)置滾動條位置時(shí)使用動畫過渡 |
enable-back-to-top | Boolean | false | iOS點(diǎn)擊頂部狀態(tài)欄、安卓雙擊標(biāo)題欄時(shí),滾動條返回頂部,只支持豎向 |
bindscrolltoupper | EventHandle | 滾動到頂部/左邊,會觸發(fā) scrolltoupper 事件 | |
bindscrolltolower | EventHandle | 滾動到底部/右邊,會觸發(fā) scrolltolower 事件 | |
bindscroll | EventHandle | 滾動時(shí)觸發(fā),event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY} |
使用豎向滾動時(shí),需要給<scroll-view/>
一個固定高度,通過 WXSS 設(shè)置 height。
示例代碼:
<view class="section"> <view class="section__title">vertical scroll</view> <scroll-view scroll-y style="height: 200px;" bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}"><view id="green" class="scroll-view-item bc_green"></view><view id="red" class="scroll-view-item bc_red"></view><view id="yellow" class="scroll-view-item bc_yellow"></view><view id="blue" class="scroll-view-item bc_blue"></view> </scroll-view> <view class="btn-area"><button size="mini" bindtap="tap">click me to scroll into view </button><button size="mini" bindtap="tapMove">click me to scroll</button> </view></view><view class="section section_gap"> <view class="section__title">horizontal scroll</view> <scroll-view class="scroll-view_H" scroll-x="true" style="width: 100%"><view id="green" class="scroll-view-item_H bc_green"></view><view id="red" class="scroll-view-item_H bc_red"></view><view id="yellow" class="scroll-view-item_H bc_yellow"></view><view id="blue" class="scroll-view-item_H bc_blue"></view> </scroll-view></view>
var order = ['red', 'yellow', 'blue', 'green', 'red'] Page({ data: { toView: 'red', scrollTop: 100 }, 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 + 1] })break } } }, tapMove: function(e) {this.setData({ scrollTop: this.data.scrollTop + 10}) } })
tip
: 請勿在scroll-view
中使用textarea
、map
、canvas
、video
組件
tip
: scroll-into-view
的優(yōu)先級高于scroll-top
tip
: 在滾動scroll-view
時(shí)會阻止頁面回彈,所以在scroll-view
中滾動,是無法觸發(fā)onPullDownRefresh
tip
: 若要使用下拉刷新,請使用頁面的滾動,而不是scroll-view
,這樣也能通過點(diǎn)擊頂部狀態(tài)欄回到頁面頂部
以上是“微信小程序中scroll-view怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。