新聞中心
- scroll-view 可滾動視圖區(qū)域
- 屬性說明
- 示例
- 代碼示例 1:縱向滾動
- 代碼示例 2:橫向滾動
- Bug & Tip
- 常見問題
- Q:scroll-view 的 scroll-top 設置是否是無效的?
- Q:scroll-view 的 scroll-top 設置是否是無效的?
scroll-view 可滾動視圖區(qū)域
解釋:可滾動視圖區(qū)域,可實現(xiàn)橫向滾動和豎向滾動。使用豎向滾動時,需要給定該組件一個固定高度,可以通過 CSS 設置 height 。

屬性說明
| 屬性名 | 類型 | 默認值 | 必填 | 說明 |
|---|---|---|---|---|
scroll-x |
Boolean |
false |
否 |
允許橫向滾動 |
scroll-y |
Boolean |
false |
否 |
允許縱向滾動 |
upper-threshold |
Number/String |
50 |
否 |
距頂部 / 左邊多遠時(單位 px),觸發(fā) scrolltoupper 事件 |
lower-threshold |
Number/String |
50 |
否 |
距底部 / 右邊多遠時(單位 px),觸發(fā) scrolltolower 事件 |
scroll-top |
Number/String |
否 |
設置豎向滾動條位置。要動態(tài)設置滾動條位置,用法 | |
scroll-left |
Number/String |
否 |
設置橫向滾動條位置。要動態(tài)設置滾動條位置,用法 | |
scroll-into-view |
String |
否 |
值應為某子元素 id(id 不能以數(shù)字開頭)。設置滾動方向后,按方向滾動到該元素,動態(tài)設置用法 | |
scroll-with-animation |
Boolean |
false |
否 |
在設置滾動條位置時使用動畫過渡 |
enable-back-to-top |
Boolean |
false |
否 |
iOS 點擊頂部導航欄、安卓雙擊標題欄時,滾動條返回頂部,只支持豎向 |
bindscrolltoupper |
EventHandle |
否 |
滾動到頂部 / 左邊,會觸發(fā) scrolltoupper 事件 | |
bindscrolltolower |
EventHandle |
否 |
滾動到底部 / 右邊,會觸發(fā) scrolltolower 事件 | |
bindscroll |
EventHandle |
否 |
滾動時觸發(fā), |
示例
跳轉編輯工具
在開發(fā)者工具中打開
在 WEB IDE 中打開
掃碼體驗
代碼示例
請使用百度APP掃碼
代碼示例 1:縱向滾動
- SWAN
- JS
縱向滾動 class="scroll-view"scroll-yupper-threshold="1"lower-threshold="1"scroll-top="{= scrollTop =}"scroll-into-view="{= scrollIntoView =}"scroll-with-animation="true"enable-back-to-top="true"bindscrolltoupper="upper"bindscrolltolower="lower"bindscroll="scroll">A B C 下一頁 滾動 回頂部
代碼示例 2:橫向滾動
- SWAN
- JS
橫向滾動 class="scroll-view"scroll-xbindscrolltoupper="toLeft"bindscrolltolower="toRight"scroll-left="{= scrollLeft =}"upper-threshold="1"lower-threshold="1"bindscroll="scroll">A B C
Bug & Tip
- Tip:請勿在 scroll-view 中使用 textarea、map、canvas、video 組件;詳情請參考原生組件說明。
- Tip:scroll-into-view 的優(yōu)先級低于 scroll-top、scroll-left 。
- Bug:在滾動 scroll-view 時會阻止頁面回彈,所以在 scroll-view 中滾動,是無法觸發(fā) onPullDownRefresh 。
- Tip:若要使用下拉刷新,請使用頁面的滾動,而不是 scroll-view 。
- Tip:scroll-into-view、scroll-top、scroll-left 需要在頁面數(shù)據(jù)高度(或?qū)挾龋伍_時生效,若有異步加載數(shù)據(jù),請在數(shù)據(jù)渲染完成時,重新動態(tài)賦值,才可生效。
- Tip:在設置 scroll-view 組件 height 屬性不是內(nèi)容可視區(qū)總高度時,使用 swan.pageScrollTo API 無法生效。
- Tip:暫不支持 border-radius 特性。
常見問題
Q:scroll-view 的 scroll-top 設置是否是無效的?
A:使用豎向滾動時,需要給
代碼示例
在開發(fā)者工具中打開
在開發(fā)者工具中打開
在 WEB IDE 中打開
- SWAN
- JS
縱向滾動 scroll-ystyle="height: 1.66rem;"scroll-into-view="{= toView =}"scroll-top="{= scrollTop =}">A B C 回頂部
分享標題:創(chuàng)新互聯(lián)百度小程序教程:scroll-view可滾動視圖區(qū)域
文章出自:http://www.dlmjj.cn/article/djeghop.html


咨詢
建站咨詢
