H5 CSS 滚动条隐藏 (横向/纵向)

1、纵向

全局隐藏- 最外层css样式上增加 -webkit-scrollbar

.time_plan_detail_warp {
  height: 100vh;
  overflow-y: scroll;
  &::-webkit-scrollbar {
    display: none;
  }
}

2、横向

思路:代码取巧,两层div,固定高度,内高度比外高度多20px,然后padding-bottom: 20px

vue,开箱即用的代码(代码有自身的逻辑部分,可忽略)

<template>
  <div class="time_profit_warp">
    <div class="time_profit_center">
      <div
        v-for="(item, index) in iconArray"
        :key="index"
        :class="['profit_item', iconArray.length > 4 ? 'item_more_four' : '']"
      >
        <div class="profit_img" @click="toPrpofit(item.target)">
          <!-- <img :src="item.img" alt="" /> -->
        </div>
        <div class="profit_word">横向滚动</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';

@Component({ name: 'ProfitIcon' })
export default class ProfitIcon extends Vue {
  private iconArray: any = ['0', '1', '2', '3', '4', '5'];

  toPrpofit(target: any) {
    if (target) {
      window.location.href = target;
    }
  }
}
</script>
<style lang="scss">
.time_profit_warp {
  padding-bottom: r(24);
  height: r(220);
  overflow: hidden;
  border: 1px solid white;
  .time_profit_center {
    height: r(240);
    display: flex;
    justify-content: flex-start;
    overflow: auto;
  }
  .profit_item {
    display: flex;
    padding-bottom: r(40);
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    min-width: r(168);
    border: 1px solid green;
    .profit_img {
      width: r(96);
      height: r(96);
      border: 1px solid red;
      border-radius: 50%;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .profit_word {
      margin-top: r(16);
      font-size: r(26);
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(255, 255, 255, 0.6);
      line-height: r(32);
      white-space: nowrap;
      text-align: center;
    }
  }
  .profit_item:last-child {
    margin-right: 0;
  }
  .item_more_four {
    min-width: r(150);
  }
}
</style>

### 如何在 UniApp H5 环境下去掉或隐藏页面滚动条 为了有效处理UniApp H5环境下的滚动条显示问题,可以采用CSS样式控制的方式。对于整个页面级别的滚动条隐藏,可以通过全局样式表来定义: ```css /* 隐藏浏览器默认的滚动条 */ html, body { overflow: hidden; } ``` 当目标是在特定容器内隐藏滚动条而非整体页面时,则需针对该容器应用自定义类名并设置相应属性[^3]。 如果仅希望移除`<scroll-view>`组件内部产生的滚动条而不影响其他部分的功能性,那么推荐使用如下方法: #### 方法一:通过 CSS 属性 `::-webkit-scrollbar` 此方式适用于Webkit内核浏览器(如Chrome、Safari),能够很好地作用于iOS设备上的H5页面中由`<scroll-view>`引发的视觉干扰现象。 ```css /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ .scroll-class ::-webkit-scrollbar{ width: 0px; height: 0px; background-color: transparent; } /* 定义滚动条轨道 内阴影+圆角*/ .scroll-class ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.1); border-radius: 8px; background-color: #F5F5F5; } /* 定义滑块 内阴影+圆角*/ .scroll-class ::-webkit-scrollbar-thumb{ border-radius: 8px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); background-color: #c8c8c8; } ``` 上述代码片段中的`.scroll-class`应替换为你实际使用的类名称,并将其应用于含有`<scroll-view>`标签的对象之上。 另外一种更为通用的做法是利用JavaScript动态调整元素样式,在某些特殊场景下可能更加灵活适用。不过考虑到性能因素,除非必要否则不建议频繁操作DOM结构。 最后值得注意的是,虽然这些技术手段可以在很大程度上改善用户体验,但在设计之初就应当充分考虑交互逻辑合理性,避免因过度追求美观而牺牲易用性的做法。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值