Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4: how to hide ScrollBar in ion-content

I'm trying to hide the scroll-bar in ion-content (Ionic 4) there's no ion-scroll on ionic 4 so I used the ion-content but I can't find any css attribute to hide it (most of them not work)

I do want to scroll but I don't want to see the scrollbar

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

I've tried it but it doesn't work in ion-content.

like image 613
Roishuk Avatar asked Jan 19 '19 12:01

Roishuk


People also ask

How do I stop ion-content scrollable?

Content Scrolling Disable Enable IONIC Framework - We can disable/enable scrollbar pragmatically. There are some some example are give, you your suitable. Example 1 - Try a setting <content scroll="false"> that will disable scrolling.

How do I enable scrolling in Ionic?

Native scrolling can be enabled using overflow-scroll=”true” on your ion-content or using the $ionicConfigProvider to set it globally in current versions of Ionic.


4 Answers

Because of Ionic use shadow DOM for ion-content, should disable scroll in element on shadow DOM and after that make ion-content his own scroll and then hide scroll bar for ion-content. The result's ion-content with the hidden working scroll bar. Need to use CSS Custom Properties. Add styles to global scope.

ion-content {
  // overwrite inline styles
  --offset-bottom: auto!important;
  --overflow: hidden;
  overflow: auto;
  &::-webkit-scrollbar {
    display: none;
  }
}
like image 102
Sergey Oleynikov Avatar answered Oct 18 '22 03:10

Sergey Oleynikov


In Ionic 4 you must use following, because Ionic use shadow DOM:

global.scss

.no-scroll {
    --overflow: hidden;
}

and in page

<ion-content class="no-scroll">
like image 38
Rostislav Avatar answered Oct 18 '22 03:10

Rostislav


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

ion-content {
 --offset-bottom: auto!important;
 --overflow: hidden;
 overflow: auto;
 &::-webkit-scrollbar {
   display: none;
 }
 }
like image 7
Felix Niedermann Avatar answered Oct 18 '22 04:10

Felix Niedermann


The <ion-content> is a custom element with shadom DOM. There's something called the ::part pseudo element to target an element in a shadom DOM element. If you look at the shadow dom, you will see this:

ion-content

Take notice of the part="scroll". Ionic did add parts to their elements that we can use via the ::part pseudo element to target this and apply our custom css to hide the scrollbar:

ion-content::part(scroll)::-webkit-scrollbar {
   display: none;
}

Tested this on iOS and Android successfully. I'm not getting it to work on Chrome though.

like image 4
Kevin Boosten Avatar answered Oct 18 '22 04:10

Kevin Boosten