Ionic 2: Hide scroll-bar and keep scrolling

半城伤御伤魂 提交于 2019-12-05 12:17:32

First and foremost, changing natural behavior of the browser and expected user experience is a risky move.

However, if you still really really want to, I think your best bet is to fake it. In this case, setting width to 0 should be enough but I'm also changing background colors to be completely transparent.

div{
  background: gray;
  height: 200px;
  overflow-y: scroll;
}

p{
  border-bottom: 1px solid black;
}

div::-webkit-scrollbar {
  border:none;
  width:0;
  background: rgba(0,0,0,0);
}
 
div::-webkit-scrollbar-track {
  border:none;
  width:0;
  background: rgba(0,0,0,0);
}
 
div::-webkit-scrollbar-thumb {
  border:none;
  width:0;
  background: rgba(0,0,0,0);
}
<div>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
  <p>content</p>
</div>

Just add below line to your css/scss file and it will work just fine.

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

Please add this to the .scss file.

.scroll-content {
    overflow-y: auto;
}

To override in the whole app, add it to the app.scss file.

Just apply this css, it working very well for me:

@media only screen and (min-width: 1025px) {
    .scroll-content:not(.show-scrollbar) {
        margin-right: -17px;
        overflow-y: scroll;
    }
}

you may improve the media query to attach only the desktop browser.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!