60

I am using the latest version of Phonegap on IOS (ipad) and I can't seem to disable the vertical overscroll/bounce on the whole app. I don't mind it on inner elements but it looks rather strange when you swipe up or down and the whole app bounces up and down.

I've tried setting UIWebViewBounce to no in the .plist however that doesn't seem to have done anything.

Appreciate the help :)

Josh Undefined
  • 1,496
  • 5
  • 16
  • 27

20 Answers20

205

You have to modify a property in your config.xml file. Just set the following preference to true

<preference name="DisallowOverscroll" value="true" />
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
dpfauwadel
  • 3,866
  • 3
  • 23
  • 40
  • 7
    Since Cordova 2.6, UIWebViewBounce has been changed to DisallowOverscroll. http://docs.phonegap.com/en/3.1.0/guide_platforms_ios_upgrading.md.html#Upgrading%20iOS – Reborn Nov 20 '13 at 17:07
  • where can i find this config.xml in iphone app? – Pulah Nandha Jan 02 '14 at 10:24
  • 1
    I found several different config.xml files There is one in the main directory and I change it there. But then when I build the app for iOS two more config.xml files are then created, one in the platforms/ios directory and one in platforms/iOS/www. The one in platforms/ios seems to have a lot more stuff then the one that I was editing in my main directory (including the preference for disallowing overscroll). – Chase Roberts Jan 03 '14 at 19:23
  • Adding this setting to the config.xml in my main project folder fixed it for me in iOS8. – bsegraves Jul 25 '14 at 01:57
  • @ChaseRoberts, config.xml from root folder is for Cordova CLI, and config.xml from www is for Adobe Phonegap Build. – andreszs Feb 01 '15 at 14:35
  • 4
    For anyone arriving late to the party: just wanted to confirm this works for CLI-6.5.0 and iOS 10 – robro Jul 27 '17 at 19:56
  • I want to confirm that it does NOT work on CLI-6.5.0 and WP8 Windows-Universal platform. Overscroll persists as usual. – andreszs Sep 15 '17 at 00:58
  • 1
    This is working fine for cordova 7.1.0 and ios 11. Remember in ios project there are two config.xml . Modify both of them correctly to get this working. – Ankit J Dec 11 '17 at 07:17
  • @AnkitJ What do you mean in ios projects there are two config.xml files? Shouldn't there just be one for both android and ios using cordova? – Joshua Jan 19 '18 at 12:05
  • @Josh Just change the only one config.xml. – Halt Jul 16 '18 at 08:54
21

The accepted answer did not work for me, I had to set UIWebViewBounce to false:

<preference name="UIWebViewBounce" value="false" />
Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
  • I'm using version 3.4 of cordova so it didn't work. But this did the job: http://stackoverflow.com/questions/22294677/phonegappreventing-bounce-only-in-the-main-window – Telmo Dias May 15 '14 at 10:37
  • `UIWebViewBounce` has been renamed to `DisallowOverscroll` and the value has been inverted, yet as of CLI 6.5.0 it does not work for Windows Universal (WP8) apps. – andreszs Sep 15 '17 at 00:59
15

now for phonegap 3.0 above version use below syntex in config.xml file and it will works 100%

<preference name="DisallowOverscroll" value="true"/>
Mayur
  • 503
  • 1
  • 6
  • 17
6

If you're adding <preference name="DisallowOverscroll" value="true"/> to config.xml without any luck, you may be changing the wrong file. Instead, search the entire phonegap directory for "DisallowOverscroll." You should find several instances. Change those to true.

Cheers.

Jerad
  • 594
  • 7
  • 15
  • I didn't find any other instances of this other than the lines in config.xml that I myself added. – Mr. TA Jun 19 '16 at 01:54
5

In config.xml of your project, under preferences for iOS set DisallowOverscroll to true. By default it is false which makes whole view to scroll along with inner elements of the view.

<preference name="DisallowOverscroll" value="true" />
user3085992
  • 163
  • 1
  • 11
4

If nothing else works, try to remove -webkit-overflow-scrolling: touch from your css...if you had it!

dom
  • 211
  • 2
  • 4
  • 2
    The problem is that also disables velocity scrolling. – Mr. TA Jun 19 '16 at 01:53
  • Yah, I've been trying to solve this problem for awhile and I basically came to the conclusion that it isn't possible to disable over-scrolling bounce without also disabling velocity scrolling, without mimicking velocity in javascript. – Norman Breau Apr 04 '17 at 13:28
4

Use this way:-

function disallowOverscroll(){
  $(document).on('touchmove',function(e){
    e.preventDefault();
  });
  $('body').on('touchstart','.scrollable',function(e) {
    if (e.currentTarget.scrollTop === 0) {
      e.currentTarget.scrollTop = 1;
    } else if (e.currentTarget.scrollHeight
              === e.currentTarget.scrollTop
                  + e.currentTarget.offsetHeight) {
      e.currentTarget.scrollTop -= 1;
    }
  });
  $('body').on('touchmove','.scrollable',function(e) {
    e.stopPropagation();
  });
}
disallowOverscroll();

For more details or Tips & Tricks, please read this article click

vineet
  • 13,832
  • 10
  • 56
  • 76
3

In config.xml of your project, under preferences for iOS set DisallowOverscroll to true.

<preference name="DisallowOverscroll" value="true" />
PRBEHERA8
  • 31
  • 5
3

There is a way I used to achieve this. but it's not conventional because it's dealing with native coding. In the MainViewController there is a method named webViewDidFinishLoad. Include this
theWebView.scrollView.bounces= NO;

inside that method.

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
    // Black base color for background matches the native apps
    theWebView.backgroundColor = [UIColor blackColor];
    theWebView.scrollView.bounces= NO;
    return [super webViewDidFinishLoad:theWebView];
}

As this is ios native code this'll work in any phonegap/cordova distribution.

Asanka Indrajith
  • 353
  • 3
  • 13
3

Thanks For All answer. But If you have issue in windows Phone here is the solution. Just go to MainPage.xaml.cs file and replace below function..

public MainPage()
    {
        InitializeComponent();
        this.CordovaView.DisableBouncyScrolling = true;
        this.CordovaView.Loaded += CordovaView_Loaded;
    }

Its works for me :)

Mayur
  • 503
  • 1
  • 6
  • 17
2

I had a similar issue, but couldn't fix it with all solutions I found so far (like editing config.xml).

But finally, simply editing the body's CSS property then it fixed:

html,body
{
  overflow: auto;
  height:100%;
}
Hanho Kim
  • 61
  • 3
2

Try This One If you are ionic framework user Abc.html file inside content.

<ion-content has-bouncing="false">

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73
1

Use this:

<preference name="UIWebViewBounce" value="false" />
1

this is what worked for my app running phonegap 3.0: add the following line to config.xml

<preference name="webviewbounce" value="false"/>
tschueggi
  • 49
  • 3
1

This worked for me. Try adding this code in config.xml file of your phonegap app:

<preference name="DisallowOverscroll" value="true">

Devid Farinelli
  • 7,514
  • 9
  • 42
  • 73
Akshay Khale
  • 8,151
  • 8
  • 50
  • 58
1

It is better to modify two elements in config.xml as follows:

<preference name="DisallowOverscroll" value="true"/>
<preference name="UIWebViewBounce" value="false" />
Nakket
  • 620
  • 7
  • 18
1

For Cordova 7 and an iPhone 7 + iOS 11.0.3, modifying the root-directory config.xml and adding this worked beautifully:

<platform name="ios">
    <preference name="DisallowOverscroll" value="true" />
    <preference name="UIWebViewBounce" value="false" />
    ... (other stuff) ...
</platform>
codeHot
  • 431
  • 4
  • 6
0

Open xCode -> find and click on config.xml from left menu-> and change DisallowOverscroll value false to true Or use this code by replacing previous.

 <preference name="DisallowOverscroll" value="true" />
Somnath
  • 368
  • 2
  • 9
  • 22
0

After update the the config.xml I had not luck, if that is your case try this.

For iOS works on iPhone + iOS 11, on CDVThemeableBrowser.m file, set property as YES:

self.disallowoverscroll = YES;
0

DisallowOverscroll does not work for me.

Solution is to ensure that there is nowhere to scroll.

For example, in my case it was div wider (it can be higher) than the body like below:

<body>
  <div style="margin: 5%" width: 95%;>something</div>
</div>

Now, above div is 5% bigger than body that cause scrolling. Set width to 90% fixes the issue.

Yuriy N.
  • 4,936
  • 2
  • 38
  • 31