6

I want to make html5 fullscreen app. I made a page and added it as an icon to my iphone. I added metatags:

 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <meta name="viewport" content="width=device-width, user-scalable=no" />

What I wanted to achieve is: black status bar on top (this does not work and I do not know why. It is still default status bar...anyone ideas?) without possibility to zoom (like in facebook app) - this works fine.

Now the problem - I can scroll on my iphone even if my app fits on the screen. It bounces back, but I dont want this behavior. I would like to disable that and enable scrolling for a particular div (.ui-content). How can I achieve that?

EDIT: status bar is black now. It changed itself after some time. Was the previous version cached on the iphone or what?

Per Hornshøj-Schierbeck
  • 15,097
  • 21
  • 80
  • 101
Michal B.
  • 5,676
  • 6
  • 42
  • 70

3 Answers3

15

This will prevent scrolling on the whole page

document.ontouchmove = function(e) {e.preventDefault()};

In your case, where you want some divs to be scrollable, and some not to, you should be able to catch the event before it gets to the document

scrollableDiv.ontouchmove = function(e) {e.stopPropagation()};
dmanxiii
  • 51,473
  • 10
  • 33
  • 23
  • 1
    Is this solution working for you? This indeed stopped the bouncing when running from within safari, when on the stand-alone web page (via the "add to home page" link) the page keeps bouncing... – liorda Apr 14 '13 at 18:27
  • 1
    Good attempt, works for most part. Except when the element that has scrolling enabled is scrolled to the top or bottom. Then the bounce effect is still triggered. – mrt Jul 29 '13 at 11:15
  • While this works, I've encountered problems where this seems to cause tap/click interactions like buttons to fail sometimes (presumably, if there was any movement of the contact while triggering the click). For now my workaround for that is to not call preventDefault if e.target is a button, link, or input element. – Brandon Paddock Sep 21 '15 at 20:08
1

If your using Cordova 1.7+, open the Cordova.plist file and set the key UIWebViewBounce to NO

Thierry Blais
  • 2,848
  • 22
  • 41
  • Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead: http://stackoverflow.com/a/12394389/419 – Kev Sep 12 '12 at 21:58
1

Extending dmanxii's approach here is what we are doing.

    $("body").on("touchmove", function (event) {
        if ($(event.target).is(".WhatEverClass") || $(event.target).parentsUntil().is(".ParentClass")) {
            //console.log("NOT Disabled"); 
        }
        else {
            //console.log("Disabled"); 
            event.preventDefault();
        }
    });
AbidCharlotte49er
  • 914
  • 1
  • 8
  • 11