Ionic 2 disable scroll

前端 未结 9 1162
暗喜
暗喜 2021-02-03 21:00

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

相关标签:
9条回答
  • 2021-02-03 21:28

    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.

    0 讨论(0)
  • 2021-02-03 21:39

    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);
          }
        }
    
    0 讨论(0)
  • 2021-02-03 21:39

    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!

    0 讨论(0)
  • 2021-02-03 21:40

    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>
    
    0 讨论(0)
  • 2021-02-03 21:44

    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;
    }
    
    0 讨论(0)
  • 2021-02-03 21:46

    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;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题