Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable scroll for ion-content in ionic 2? #7644

Closed
rhuldip opened this issue Aug 10, 2016 · 30 comments
Closed

How to disable scroll for ion-content in ionic 2? #7644

rhuldip opened this issue Aug 10, 2016 · 30 comments
Labels
ionitron: v3 moves the issue to the ionic-v3 repository

Comments

@rhuldip
Copy link

rhuldip commented Aug 10, 2016

Note: If you are having problems formatting your issue please refer to this article on using markdown in Github:

https://guides.github.com/features/mastering-markdown/

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

What behavior are you expecting?

Steps to reproduce:
1.
2.
3.

insert any relevant code between the above and below backticks

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Which Ionic Version? 1.x or 2.x

Plunker that shows an example of your issue

For Ionic 1 issues - http://plnkr.co/edit/Xo1QyAUx35ny1Xf9ODHx?p=preview

For Ionic 2 issues - http://plnkr.co/edit/me3Uk0GKWVRhZWU0usad?p=preview

Run ionic info from terminal/cmd prompt: (paste output below)

@Ionitron Ionitron added the v2 label Aug 10, 2016
@rhuldip
Copy link
Author

rhuldip commented Aug 10, 2016

i dont want to hijack my browser,any other option by ionic team?

@jgw96
Copy link
Contributor

jgw96 commented Aug 10, 2016

Hello! Thanks for using Ionic! We actually just documented a method called setScrollDisabled that will allow you to do this. You can see the documentation in this commit. Thanks for using Ionic!

@jgw96 jgw96 closed this as completed Aug 10, 2016
@rhuldip
Copy link
Author

rhuldip commented Aug 10, 2016

Hi,any example how can i use it?

julien-tmp referenced this issue Aug 10, 2016
documented setEnabled, setScrollDisabled methods
@julien-tmp
Copy link

julien-tmp commented Aug 10, 2016

Hi @rhuldip . As I understood on another page, you wanted to disable the scroll for and not for the whole app. In this case you can use :

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

and then, in your SCSS file :

[noScroll] {
  overflow: hidden;
}

credits to @mhartington for the guidance

@DahliaWitt
Copy link

Is there a directive for this? The documentation mentions it but it does not work.

@dgroh
Copy link

dgroh commented Aug 16, 2016

Below I show how this can also be solved:

Create thoses classes in some of zour scss files, i.e app.scss

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

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

Then just call:

this.content.addCssClass("no-scroll");

or

this.content.addCssClass("scroll");

Where content is:

@Input("content") protected content: Content;

Hope this helps

@haxpor
Copy link

haxpor commented Oct 25, 2016

Thanks @dgroh , it works really well on my end as of Ionic Framework Version: 2.0.0-rc.1.
Just curious, should scroll-content be .scroll-content as it's class? But it's not that important. Thanks again.

@0x1ad2
Copy link

0x1ad2 commented Dec 1, 2016

I used the following SO answer to fix it http://stackoverflow.com/a/40826366/1783311

Add this to your .scss file

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

then add the no-scroll class to your ion-content like this

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

@iflagri
Copy link

iflagri commented Dec 7, 2016

I solved it as below.

<ion-content>
   <div ion-fixed>
   </div>
</ion-content>

@AjkP
Copy link

AjkP commented Jan 19, 2017

Hello! Thanks for using Ionic! We actually just documented a method called setScrollDisabled that will allow you to do this. You can see the documentation in this commit. Thanks for using Ionic!

@jgw96 This does not work after RC4. Should we reopen this?

@shyamal890
Copy link

@jgw96 please consider adding this functionality, its much needed.

@theomathieubhvr
Copy link

@iflagri solution works. Thanks !

@larssn
Copy link

larssn commented Feb 15, 2017

If anyone is still having trouble with this, add no-bounce to ion-content, and see if that fixes it.

<ion-content no-bounce></ion-content>

@primerproyecto
Copy link

@larssn fix it. Thanks !

@nan-ser0
Copy link

@larssn Fix it. ty!

@eymen-elkum
Copy link

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;
        }
    }
}

@mlynch mlynch reopened this May 31, 2017
@mlynch
Copy link
Contributor

mlynch commented May 31, 2017

Need to support disabling scrolling through an attribute on <ion-content>

@pjc2007
Copy link

pjc2007 commented Jun 12, 2017

I have an issue on iOS, where if I have a select doing a scrolling gesture on it scrolls the contents underneath, so I want to disable the scroll when the select is up.

None of the above seems to work for me. I've tried the no-bounce, and also directly added an inline style of style='overflow-y : hidden' just to see if this will stop the scrolling, (so I can then later set it dynamically) but it doesn't.

@pjc2007
Copy link

pjc2007 commented Jun 12, 2017

In my case, I had to set this scroll in code, as it is the nested div with the class scroll-content that I needed to add the overflow:hidden to.

To do this in code, I did the following...

 @ViewChild(Content) content: Content;
  ....

  private setDisableScroll(disable: boolean) : void {       
     let scroll = this.content.getScrollElement();
     scroll.style.overflowY = disable ? 'hidden' : 'scroll';                    
    }

@gonzag
Copy link

gonzag commented Jun 19, 2017

@pjc2007, you made my day

@KeaganFouche
Copy link

KeaganFouche commented Jul 5, 2017

@iflagri thank you so much! I was struggling for a few days now, the solution which worked for me was:

<ion-content>
  <span ion-fixed style="height: 100%; width: 100%">
 //all other HTML is here...
</span>
</ion-content>

@Sampath-Lokuge
Copy link

The only solution which works for me. Thanks @KeaganFouche

@sertal70
Copy link

sertal70 commented Nov 6, 2017

The only working solution for me is @iflagri one. I'm wondering why a div is needed, I tried to put ion-fixed directive directly on ion-content but it doesn't work.

no-bounce simply doesn't work all the time.

@saurabhschauhan
Copy link

Adding this in config.xml works or me.

<preference name="webviewbounce" value="false" /> <preference name="UIWebViewBounce" value="false" /> <preference name="DisallowOverscroll" value="true" />

@enriquerene
Copy link

I don't know why exactly you want to remove it, but if because of the fixed height of the ion-content when call page-x tags in a main html file, I solved this inserting ion-grid and after the page tags. Further, I removed the ion-content of the inner pages and all html are wrapped in ion-row, as my home.html (sorry, I couldn't put code in blocks, the preview always gave me inline):

<ion-content no-padding> <ion-grid no-padding> <div class="bg-gradient-light"> <img src="../../assets/imgs/logo.png" /> </div> <page-features></page-features> <page-categories></page-categories> <page-social class="before-footer"></page-social> </ion-grid> </ion-content>

and all my page-pageName has this structure:

<ion-row> <ion-col ...> <!-- content here --> </ion-col> </ion-row>

@shanemac10
Copy link

Here's how I handled it, which seems like the more natural approach to me. Just open your src/app/app.scss (Where your global styles should live) and add...
.scroll-content { overflow-y: auto; }
Done.

I don't know why you would want to force scroll or hidden, when your style should be dynamic to the content in most cases. If you have a special case, go ahead and hard code it, but in general, I don't understand why Ionic has this overridden to scroll.

@chriskuech
Copy link

Every single page has a scrollbar by default that only scrolls at most a couple pixels. This should be considered a bug. The no-bounce fix above appears to work, but should not need to be added to every non-scrolling view.

@adamdbradley adamdbradley added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 1, 2018
@imhoffd imhoffd added ionitron: v3 moves the issue to the ionic-v3 repository and removed ionitron: v3 moves the issue to the ionic-v3 repository labels Nov 1, 2018
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 1, 2018

Thanks for the issue! We have moved the source code and issues for Ionic 3 into a separate repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

Thank you for using Ionic!

@imhoffd imhoffd removed the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 28, 2018
@Ionitron Ionitron added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 28, 2018
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!

Thank you for using Ionic!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

Issue moved to: ionic-team/ionic-v3#123

@ionitron-bot ionitron-bot bot closed this as completed Nov 28, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: v3 moves the issue to the ionic-v3 repository
Projects
None yet
Development

Successfully merging a pull request may close this issue.