javascript 使滚动条在移动的浏览器中不可见

ej83mcc0  于 9个月前  发布在  Java
关注(0)|答案(2)|浏览(145)

我想隐藏滚动条,而不禁用滚动
我在CSS中使用了这个规则:

::-webkit-scrollbar {
  display: none;
}

字符串
我也试过:

::-webkit-scrollbar {
  width: 0;
}


从PC,它工作正常,在移动的,无论浏览器,我已经尝试了Safari和Chrome,它不工作.

ha5z0ras

ha5z0ras1#

/* You can adjust your break point on the width to say when you want it visible */

@media screen and (max-width: 767px) {
  body {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  body::-webkit-scrollbar {
    display: none;
  }
}

.test {
  height: 1000px;
}

个字符

ma8fv8wu

ma8fv8wu2#

除了上面KnightTheLion的答案,对于任何发现这个问题并使用LESS的人,你可以使用mixins来方便:

// LESS media query mixin template

@screen-phone: 767px;
@screen-tablet: 922px;
@screen-desktop: 1200px;

.media-phone(@rules) {
  @media screen and (max-width: @screen-phone) {
    @rules();
  }
}

.media-tablet(@rules) {
  @media screen and (min-width: (@screen-phone + 1px)) and (max-width: (@screen-desktop - 1px)) {
    @rules();
  }
}

.media-desktop(@rules) {
  @media screen and (min-width: @screen-desktop) {
    @rules();
  }
}

.media-custom-max(@width, @rules) {
  @media screen and (max-width: @width) {
    @rules();
  }
}

.media-custom-min(@width, @rules) {
  @media screen and (min-width: @width) {
    @rules();
  }
}

// gt=greater than
.media-gt-phone(@rules) {
  @media (min-width: (@screen-phone + 1px)) {
    @rules();
  }
}

.media-gt-tablet(@rules) {
  @media (min-width: (@screen-tablet + 1px)) {
    @rules();
  }
}

字符串
下面是一个使用示例:

body {
  .media-phone ({
    scrollbar-width: none;
    -ms-overflow-style: none;
  });

}
body::-webkit-scrollbar {
  .media-phone ({
  display: none;
  });
}


您可以随时添加更多的mixin并编辑现有的mixin,以适应更宽的屏幕和更多内容。

相关问题