简体   繁体   English

如何在移动浏览器中隐藏滚动条?

[英]How to hide scroll bar on mobile safari?

I made navbar usign jade: 我做了Navbar USIG玉:

nav.navbar.navbar_white
    div.navbar__inner
        ul.nav-list
            li.nav-list__item_dark
                a(href="#") item 1
            li.nav-list__item_dark
                a(href="#") item 2
            li.nav-list__item_dark
                a(href="#") item 3
            li.nav-list__item_dark
                a(href="#") item 4

And I want it to be horizontally scrollable on mobile and hide the scroll bar. 我希望它可以在移动设备上水平滚动并隐藏滚动条。 So I wrote the following scss: 所以我写了以下的scss:

.nav-list {
    padding: 15px 0;
    margin: 0;
    width: 100%;
    list-style: none;
    white-space: nowrap;
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch!important; 
    -ms-overflow-style: -ms-autohiding-scrollbar!important;

    &::-webkit-scrollbar { 
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        background-color: transparent;
    }

    &::-webkit-scrollbar-thumb {
        display: none !important;
    }
}

As you see, I tried every way I know to hide it. 如您所见,我尽我所知将其隐藏起来。 But it works only when I load the page for the first time. 但是它仅在我第一次加载页面时有效。 When I reload it the scrollbar appears again. 当我重新加载它时,滚动条再次出现。 I need help to fix it 我需要帮忙解决

The crossbrowser way to solve this problem is to set bottom padding to .navbar__inner element and set fixed height (should be less than computed height of .navbar__inner) and overflow:hidden to outer element. 解决此问题的跨浏览器方法是将底部填充设置为.navbar__inner元素,并设置固定高度(应小于.navbar__inner的计算高度),然后将overflow:hidden隐藏到外部元素。 So that the scrollbar will not be visible because it will be placed lower (and will be overlowed) than the bottom of outer element. 这样滚动条将不可见,因为它的位置将比外部元素的底部低(并被降低)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM