小程序 · 2025年4月10日

微信小程序开发实现scroll-view隐藏滚动条方法介绍

网页开发的时候往往会为了页面的美观,而选择去掉滚动区域默认的滚动条。微信小程序实现scroll-view隐藏滚动条的方法之一:

首先我们来看一下,scroll-view的一些组件

使用竖向滚动时,需要给 一个固定高度,通过 设置 height。
再来看一些简单的代码示例:

<view>
 <view>vertical scroll</view>
 <scroll-view>
 <view></view>
 <view></view>
 <view></view>
 <view></view>
 </scroll-view>
  
 <view>
 <button>click me to scroll into view </button>
 <button>click me to scroll</button>
 </view></view><view>
 <view>horizontal scroll</view>
 <scroll-view>
 <view></view>
 <view></view>
 <view></view>
 <view></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 <p><img src="https://img.php.cn//upload/image/503/661/452/1489642942174580.png" title="微信小程序开发实现scroll-view隐藏滚动条方法介绍" alt="微信小程序开发实现scroll-view隐藏滚动条方法介绍"    style="max-width:90%"  style="max-width:90%"></p><p><img src="https://img.php.cn//upload/image/885/649/303/1489642971911534.png" title="微信小程序开发实现scroll-view隐藏滚动条方法介绍" alt="微信小程序开发实现scroll-view隐藏滚动条方法介绍"    style="max-width:90%"  style="max-width:90%"></p><p>效果图如下:</p><p><img src="https://img.php.cn//upload/image/854/287/334/1489643137709656.png" title="微信小程序开发实现scroll-view隐藏滚动条方法介绍" alt="微信小程序开发实现scroll-view隐藏滚动条方法介绍"    style="max-width:90%"  style="max-width:90%"></p><p>注意:<br>(1)不能在scroll-view中使用textarea,mao,<a href="http://www.php.cn/code/7892.html" target="_blank">canvas</a>,video组件<br>(2)scroll-init-view的<a href="http://www.php.cn/code/6066.html" target="_blank">优先级</a>高于scroll-top<br>(3)onPullDownRefresh<a href="http://www.php.cn/js/js-jspopular-guide-event.html" target="_blank">事件</a>,无法在scroll-view中触发<br>(4)若想使用下拉刷新,一定要使用页面的滚动,而不是scroll-view,这样也能通过点击顶部<a href="http://www.php.cn/code/8243.html" target="_blank">状态</a>栏回到页面顶部</p>

登录后复制

以上就是微信小程序开发实现scroll-view隐藏滚动条方法介绍的详细内容,更多请关注GTHOST其它相关文章!