uniapp隐藏scroll-view滚动条

uniapp基础

本文章记录uniapp如何去除scroll-view滚动条问题



前言

这段时间会学习并使用uniapp做项目,会总结一些关于uniapp的坑以及解决方法,希望能帮助到你。


一、效果如下

请添加图片描述


<script lang="ts" setup>
const tabIndex = ref(0)
const scrollInto = ref('tab0')
const tabList = [
  {
    id: 'tab01',
    name: 'tab01',
    newsid: 0,
  },
  {
    id: 'tab02',
    name: 'tab02',
    newsid: 23,
  },
  {
    id: 'tab03',
    name: 'tab03',
    newsid: 223,
  },
  {
    id: 'tab04',
    name: 'tab04',
    newsid: 221,
  },
  {
    id: 'tab05',
    name: 'tab05',
    newsid: 225,
  },
  {
    id: 'tab06',
    name: 'tab06',
    newsid: 208,
  },
  {
    id: 'tab07',
    name: 'tab07',
    newsid: 225,
  },
  {
    id: 'tab08',
    name: 'tab08',
    newsid: 208,
  },
  {
    id: 'tab09',
    name: 'tab09',
    newsid: 225,
  },
  {
    id: 'tab10',
    name: 'tab10',
    newsid: 208,
  },
]

function ontabtap(index: number) {
  if (tabIndex.value === index)
    return

  tabIndex.value = index

  scrollInto.value = `tab${index}`
}
</script>

<template>
  <view class="tabs">
    <scroll-view
      class="tab_bar"
      scroll-x="true"
      :show-scrollbar="false"
      :scroll-into-view="scrollInto"
      :scroll-with-animation="true"
    >
      <view
        v-for="(tab, index) in tabList"
        :id="`tab${index}`"
        :key="tab.id"
        class="tab_bar_item"
        @click="ontabtap(index)"
      >
        <text
          class="tab_bar_item_title"
          :class="tabIndex === index ? 'tab_bar_item_title_active' : ''"
        >
          {{ tab.name }}
        </text>
      </view>
      <view class="tab_bar_indicator" />
    </scroll-view>
    <uni-card title="基础卡片" sub-title="副标题" extra="额外信息" :thumbnail="avatar" @click="onClick">
      <text class="uni-body">
        这是一个带头像和双标题的基础卡片,此示例展示了一个完整的卡片。
      </text>
    </uni-card>
  </view>
</template>

<style lang="scss" scoped>
// /*每个页面公共css */
// .tab_bar ::-webkit-scrollbar {
//   display: none;
//   width: 0;
//   height: 0;
//   -webkit-appearance: none;
//   background: transparent;
//   color: transparent;
// }
uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  display: none;
  width: 0;
  height: 0;
  -webkit-appearance: none;
  background: transparent;
  color: transparent;
}

.tab_bar {
  white-space: nowrap;
  width: 100%;
  background: green;
}

.tab_bar_item {
  display: inline-block;
  margin-right: 80rpx;
  height: 50rpx;
  line-height: 50rpx;
  text-align: center;
  font-size: 30rpx;
}

.tab_bar_indicator {
  width: 50rpx;
  height: 3rpx;
  background: red;
}

.tab_bar_item_title_active {
  color: red;
}
</style>

二、解决方案

设置伪元素

/*每个页面公共css */
.tab_bar ::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
  -webkit-appearance: none;
  background: transparent;
  color: transparent;
}

总结

以上就是今天分享的内容,本文简单介绍了uniapp隐藏scroll-view滚动条解决方法。希望文章对你有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明似水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值