iOS 5 has brought a number of nice things to JavaScript/Web Apps. One of them is improved scrolling. If you add
-webkit-overflow-scroll:touch;
to the style of a textarea element, scrolling will work nicely with one finger.
But there's a problem. To prevent the entire screen from scrolling, it is recommended that web apps add this line of code:
document.ontouchmove = function(e) {e.preventDefault()};
This, however, disables the new scrolling.
Does anyone have a nice way to allow the new scrolling within a textarea, but not allow the whole form to scroll?
You should be able to allow scrolling by selecting whether or not preventDefault is called. E.g.,
Alternatively, this may work by preventing the event from reaching the document level.
Edit For anyone reading later, the alternate answer does work and is way easier.
The only issue with Brian Nickel's answer is that (as user1012566 mentioned) stopPropagation doesn't prevent bubbling when you hit your scrollable's boundaries. You can prevent this with the following:
ScrollFix seems to be perfect solution. I tested it and it works like a charm!
https://github.com/joelambert/ScrollFix
It was frustrating to discover a known problem with stopPropagation and native div scrolling. It does not seem to prevent the onTouchMove from bubbling up, so that when scrolling beyond the bounds of the div (upwards at the top or downwards at the bottom), the entire page will bounce.
More discussion here and here.
For anyone trying to acheive this with PhoneGap, you can disable the elastic scrolling in the
cordova.plist
, set the value forUIWebViewBounce
toNO
. I hope that helps anyone spending ages on this (like i was).