32

I've tried several methods to disable scroll, including using CSS position: fixed, attribute overflow-scroll="false" and etc, but all methods failed.

When I swipe down, the buttons will go up and while I swipe up the buttons will go down, like bouncing effect.

May I know any solutions to this issue? Thank you very very much.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Reo Lim
  • 429
  • 1
  • 4
  • 8

10 Answers10

41

Tested with ionic 3 (should work on ionic 2):

<ion-content no-bounce></ion-content>
OriolJ
  • 2,762
  • 1
  • 28
  • 22
  • 3
    For anybody with an up to date version of Ionic – this is the best answer for the time being. See: https://github.com/ionic-team/ionic/issues/7644 – shaneparsons Jun 05 '17 at 17:17
  • After removing any element that had a bigger height than the content, this worked for me aswell – Phonolog May 30 '18 at 07:41
  • 1
    Max from Ionic here, it's clear we need to make this way easier. We're passing around this issue internally to make sure we fix this going forward! – Max Jun 07 '18 at 15:10
25

I solved same problem using css. (Ionıc 3.6)

Step1: In ion-content add a new class :

<ion-content class="no-scroll">

Step2: In your CSS add the code below :

.no-scroll .scroll-content{
    overflow: hidden;
}
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
A.Çetin
  • 250
  • 4
  • 7
8

The ion-content has a class called 'scroll-content'.

With that in mind, go to your app.css, inside the src/app and add:


app.css:

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

That should leave your ion-content with no scroll, but I'd rather user:

app.css:

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

since this allows the scroll-content only if the page content overflows the ion-content.

Caio Crespo
  • 93
  • 1
  • 6
6

This works in ionic 5:

ion-content {
   --overflow: hidden;
}

<ion-content scroll-y="false">
Mert Aksoy
  • 372
  • 1
  • 4
  • 12
3

For disable scroll in ion-content can use setScrollDisabled() method. You should follow steps below.

In hello.ts

 import { app } from 'ionic-angular';

   public class HelloPage
   {
       constructor(private app: App) {};

        ngAfterViewInit(){
        this.app.setScrollDisabled(true);
      }
    }
nahoang
  • 2,400
  • 1
  • 18
  • 22
2

If you don't want the scroll you may also don't need the ion-content itself, in my status for example I want to use the ion-grid directly.

<!-- my-page.ts >
<ion-header>.......</ion-header>
<ion-grid class="has-header fixed-content">

</ion-grid>

and I added some scss for the has-header class:

ion-app {
    &.md {
        .has-header {
            margin-top: $toolbar-md-height;
        }
    }
    &.wp {
        .has-header {
            margin-top: $toolbar-wp-height;
        }
    }
    &.ios {
        .has-header {
            margin-top: $toolbar-ios-height;
        }
    }
}
Eymen Elkum
  • 3,013
  • 1
  • 20
  • 34
2

Content is placed in the scrollable area if provided without a slot. To show a fixed content add slot="fixed".

<ion-content>
<div slot="fixed">

</div>
</ion-content>
Arun Girivasan
  • 532
  • 1
  • 10
  • 24
  • This should be marked as the answer. Using this for displaying non-scrollable skeleton-text while waiting for data to load from database. – Cooper Scott May 20 '20 at 16:49
0

As iflagri posted in this issue and @shaneparsons pointed in the comments, using

<ion-content padding>
  <div ion-fixed>

    Your content here...

  </div>
</ion-content>

Solve the problem.

Hope it help!

Rodrigo Chaves
  • 1,094
  • 8
  • 23
0

If you want to disable the content scrolling you can use

<ion-content [scrollY]="false" >

https://ionicframework.com/docs/api/content

<ion-content [attr.noScroll]="shouldScroll"></ion-content>
    
// scss file:

[noScroll] {
   overflow: hidden;
}
Siddhartha Mukherjee
  • 2,703
  • 2
  • 24
  • 29
-1

Surprisingly, no-bounce attribute did work on my previous project and is not working on a new project that I am currently working on.

I tried @rodrigo-chave's solution with ion-fixed. It solved the scrolling problem, but made my content small (as if was zoomed out). Adding 100% CSS width and height properties fixed it.

<ion-content no-bounce>
  <div ion-fixed style="height: 100%; width: 100%">
    ...
  </div>
</ion-content>
Uzbekjon
  • 11,655
  • 3
  • 37
  • 54