<p>可滚动视图区域。使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 height。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。</p><table><thead><tr class="firstRow"><th>属性</th><th>类型</th><th>默认值</th><th>必填</th><th>说明</th><th>最低版本</th></tr></thead><tbody><tr><td>scroll-x</td><td>boolean</td><td>false</td><td>否</td><td>允许横向滚动</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>scroll-y</td><td>boolean</td><td>false</td><td>否</td><td>允许纵向滚动</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>upper-threshold</td><td>number/string</td><td>50</td><td>否</td><td>距顶部/左边多远时,触发 scrolltoupper 事件</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>lower-threshold</td><td>number/string</td><td>50</td><td>否</td><td>距底部/右边多远时,触发 scrolltolower 事件</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>scroll-top</td><td>number/string</td><td><br/></td><td>否</td><td>设置竖向滚动条位置</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>scroll-left</td><td>number/string</td><td><br/></td><td>否</td><td>设置横向滚动条位置</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>scroll-into-view</td><td>string</td><td><br/></td><td>否</td><td>值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>scroll-with-animation</td><td>boolean</td><td>false</td><td>否</td><td>在设置滚动条位置时使用动画过渡</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>enable-back-to-top</td><td>boolean</td><td>false</td><td>否</td><td>iOS点击顶部状态栏、安卓双击标题栏时,滚动条返回顶部,只支持竖向</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>bindscrolltoupper</td><td>eventhandle</td><td><br/></td><td>否</td><td>滚动到顶部/左边时触发</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>bindscrolltolower</td><td>eventhandle</td><td><br/></td><td>否</td><td>滚动到底部/右边时触发</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr><tr><td>bindscroll</td><td>eventhandle</td><td><br/></td><td>否</td><td>滚动时触发,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}</td><td><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html">1.0.0</a></td></tr></tbody></table><p>Bug &amp; Tip</p><p>tip: 基础库 2.4.0以下不支持嵌套textarea、map、canvas、video 组件</p><p>tip: scroll-into-view 的优先级高于 scroll-top</p><p>tip: 在滚动 scroll-view 时会阻止页面回弹,所以在 scroll-view 中滚动,是无法触发 onPullDownRefresh</p><p>tip: 若要使用下拉刷新,请使用页面的滚动,而不是 scroll-view ,这样也能通过点击顶部状态栏回到页面顶部</p><p>示例代码</p><p>&lt;view class=&quot;section&quot;&gt;</p><p> &lt;view class=&quot;section__title&quot;&gt;vertical scroll&lt;/view&gt;</p><p> &lt;scroll-view scroll-y style=&quot;height: 200px;&quot; bindscrolltoupper=&quot;upper&quot; bindscrolltolower=&quot;lower&quot; bindscroll=&quot;scroll&quot; scroll-into-view=&quot;{{toView}}&quot; scroll-top=&quot;{{scrollTop}}&quot;&gt;</p><p> &lt;view id=&quot;green&quot; class=&quot;scroll-view-item bc_green&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;red&quot; class=&quot;scroll-view-item bc_red&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;yellow&quot; class=&quot;scroll-view-item bc_yellow&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;blue&quot; class=&quot;scroll-view-item bc_blue&quot;&gt;&lt;/view&gt;</p><p> &lt;/scroll-view&gt;</p><p> &lt;view class=&quot;btn-area&quot;&gt;</p><p> &lt;button size=&quot;mini&quot; bindtap=&quot;tap&quot;&gt;click me to scroll into view &lt;/button&gt;</p><p> &lt;button size=&quot;mini&quot; bindtap=&quot;tapMove&quot;&gt;click me to scroll&lt;/button&gt;</p><p> &lt;/view&gt;&lt;/view&gt;&lt;view class=&quot;section section_gap&quot;&gt;</p><p> &lt;view class=&quot;section__title&quot;&gt;horizontal scroll&lt;/view&gt;</p><p> &lt;scroll-view class=&quot;scroll-view_H&quot; scroll-x style=&quot;width: 100%&quot;&gt;</p><p> &lt;view id=&quot;green&quot; class=&quot;scroll-view-item_H bc_green&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;red&quot; class=&quot;scroll-view-item_H bc_red&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;yellow&quot; class=&quot;scroll-view-item_H bc_yellow&quot;&gt;&lt;/view&gt;</p><p> &lt;view id=&quot;blue&quot; class=&quot;scroll-view-item_H bc_blue&quot;&gt;&lt;/view&gt;</p><p> &lt;/scroll-view&gt;&lt;/view&gt;</p><p>var order = [&#39;red&#39;, &#39;yellow&#39;, &#39;blue&#39;, &#39;green&#39;, &#39;red&#39;]Page({</p><p> data: {</p><p> toView: &#39;red&#39;,</p><p> scrollTop: 100</p><p> },</p><p> upper: function(e) {</p><p> console.log(e)</p><p> },</p><p> lower: function(e) {</p><p> console.log(e)</p><p> },</p><p> scroll: function(e) {</p><p> console.log(e)</p><p> },</p><p> tap: function(e) {</p><p> for (var i = 0; i &lt; order.length; ++i) {</p><p> if (order[i] === this.data.toView) {</p><p> this.setData({</p><p> toView: order[i + 1]</p><p> })</p><p> break</p><p> }</p><p> }</p><p> },</p><p> tapMove: function(e) {</p><p> this.setData({</p><p> scrollTop: this.data.scrollTop + 10</p><p> })</p><p> }})</p><h2><br/></h2><h2><img src="/up_pic/201906/291015113982.png" title="291015113982.png" alt="1.png"/><br/><a href="https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html#Bug-Tip" class="header-anchor"></a><br/></h2>
T:0.007775s,M:252.02 KB
返回顶部 留言