10

I have a page which uses a scrollable <div>:

<DIV style="OVERFLOW-Y: hidden; WIDTH: 928px; OVERFLOW: scroll">
...Huge Content
</div>

Now while it works fine in desktop browsers, I am unable to scroll on the iPad.

Could you please provide a solution (preferably without the use of any 3rd party frameworks like Sencha, etc.)?

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
hmthr
  • 7,711
  • 5
  • 19
  • 13

4 Answers4

6

With iPhone and iPad, you can scroll individual elements by placing two fingers on them and dragging.

...which makes this less of a programming question really :-)

Andy E
  • 338,112
  • 86
  • 474
  • 445
  • Do you have any Apple Support URL on the same (like where they say use 2-fingers for fixed width/height div) – hmthr May 12 '11 at 10:16
  • @hmthr: close to that; the support page only says "frames" but it works for all scrollable elements. I've added it to my answer anyway. – Andy E May 12 '11 at 10:55
  • Can you generically trigger two-finger events when the one-finger events happen? This would use the native scroll functionality with minimal JS. Something like `onSingleDragStart() { doubleDragStart(); }` etc. ? – peteorpeter May 12 '11 at 14:20
  • two finger scrolling also works with `overflow: scroll;` `
    `
    – Vitim.us May 20 '12 at 05:20
  • +1 Turns out my div was scrollable already, I just didn't know I had to use 2 fingers :) – Drahcir Apr 26 '14 at 15:26
5

I realize that this is an older question but there is now a much better solution. We now have access to the -webkit-overflow-scrolling: touch; css element. See here for a demo

davehale23
  • 4,374
  • 2
  • 27
  • 40
1

There is no easy, native way to make divs scrollable with one finger, as if it were a full screen panel. You can use two fingers like Andy E says, however I doubt whether most users will know about this, and it's not very discoverable IMO.

Sencha etc can do it, however it's not real (i.e. native) scrolling, it's using all sorts of Javascript trickery to approximate it, and is liable to slow down and behave badly if you're doing anything else complex...

That said, web apps like Yahoo Mail on the iPad seem to make it work quite elegantly.

funkybro
  • 8,432
  • 6
  • 39
  • 52
  • I am not sure if you are correct when you say "no way to make divs scrollable with one finger"...You can see the demo below on an iPad; http://cubiq.org/dropbox/iscroll/index.html?v=3.7.1 And yes, it does not seem to slow down the scrolling... – hmthr May 12 '11 at 10:27
  • 1
    I've edited my answer to clarify. It can't be done out of the box, e.g. by simply adding a CSS tag or whatever. Your example uses iScroll which does the same sort of JS trickery as Sencha. – funkybro May 12 '11 at 10:46
1

I've had good success with this problem with the help of this little project: http://cubiq.org/iscroll.

Scroll down to "how to use".

EDIT, try this for only horizontal scroll (using iScroll):

HTML:

<div id="wrapper">
    <div id="scroller">
        Huge Content...
    </div>
</div>

CSS:

#wrapper {
    position:relative;
    z-index:1;
    width: 926px
    height: 200px;
    overflow: hidden;
}

JavaScript:

function loaded() {
    document.addEventListener('touchmove', function(e){ e.preventDefault(); });
    myScroll = new iScroll('scroller', {vScrollbar:false});
}

document.addEventListener('DOMContentLoaded', loaded);
Jon Nylander
  • 8,743
  • 5
  • 34
  • 45
  • Is iScroll free for commercial use? Are there any license issues? – hmthr May 12 '11 at 10:29
  • Also how do I customize it to do horizontal or vertical scrolling ? – hmthr May 12 '11 at 11:14
  • It is MIT licensed so yeah, free for commercial use. As to horizontal or vertical scrolling I am not sure. It was some time since I implemented with it. But I would expect that if your overflows are correct and you have the right size on stuff it should work out automatically. Also you can disable the horizontal or vertical scrollbars independently. – Jon Nylander May 12 '11 at 11:19
  • Hey Jon...Thanks a lot for the detailed example. I just tried implementing on my page and seem to be having 1 issue..There are some dropdowns within my scrollable area and those do not work when I use iScroll..Is this some kind of a known issue OR is there a workaround for that as well..Thanks again.. – hmthr May 12 '11 at 11:34
  • Yeah... hmm I remember having problems with form elements too. – Jon Nylander May 12 '11 at 11:49
  • Yeah, apparently a known issue. If you scroll through the issue tracker for the project http://code.google.com/p/iscroll-js/issues/list, specifically issue 1 and 10 seem to deal with your exact issue. That's too bad. – Jon Nylander May 12 '11 at 11:54
  • Yes..right..the select box not being activated is the exact issue which I am facing, as listed in the issue link you gave..Since that is a requirement for my page (actually i have a lot of form fields in my page), I guess I'll have to look for some other solution for my scrollable div issue... – hmthr May 12 '11 at 11:59
  • @Jon : Just to ask you; In your opinion, do you think if we try to edit the iscroll.js, could there be a easy way to fix this if one does some analysis OR do you think some basic things might have already been tried by the iscroll developers and still the issue has not been fixed. – hmthr May 12 '11 at 12:30
  • Since iScroll uses webkit CSS animations I think you will be fairly stuck with the form element problems. Just of the top of my head I would perhaps attempt placing elements (ex divs) on top of (higher z-index) than the form elements and see if I from them can forward the event I want to happen (presumably focus) to the underlying form element. But, If that seems dodgy or hard to get working I would probably abandon ship and go for another interaction design. – Jon Nylander May 12 '11 at 12:38
  • 1
    You're right...I'll abandon iScroll and look for some other solution..But anyways, thanks a lot and I MUST SAY THAT YOUR ANSWERS HAVE TRULY BEEN PERFECT, TO THE POINT...CAN'T ASK FOR ANYTHING BETTER..U ROCK !! – hmthr May 13 '11 at 06:35