Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontally scrollable div which contains vertical scrollable div will not scroll horizontally on iOS

Imagine a horizontally scrollable div which contains two vertically scrollable divs.
You are supposed to scroll horizontally to navigate, then scroll vertically in the inner divs to read content.

/* MINIMAL RESET */
body, html {
  height: 100%;
  margin: 0;
  padding: 0;
}
* { box-sizing: border-box; }
<div style="
            overflow-x: scroll;
            white-space: nowrap;
            width: 100%;
            height: 100%;
            position: relative;
            background-color: black;
            ">
  <div style="
              width: 100%;
              height: 100%;
              left: 0%;
              top: 0px;
              margin: 0px;
              position: absolute;
              display: inline-block;
              background-color: green;
              ">
    <div style="
                width: 100%;
                height: 100%;
                overflow-y: scroll;
                ">
      <div style="
                  width: 100%;
                  height: 200%;
                  ">
      </div>
    </div>
  </div>
  <div style="
              width: 100%;
              height: 100%;
              left: 100%;
              top: 0px;
              margin: 0px;
              position: absolute;
              display: inline-block;
              background-color: blue;
              ">
    <div style="
                width: 100%;
                height: 100%;
                overflow-y: scroll;
                ">
      <div style="
                  width: 100%;
                  height: 200%;
                  ">
      </div>
    </div>
  </div>
</div>

After looking at this question I figured out that you can set -webkit-overflow-scrolling : 'touch', but in my case I need to look for another solution, since I manipulate the horizontal scroller when the scroll has ended, and touch-scroll does in this case break it.

The following example works fine in Chrome, also Chrome on Android, however on iOS, one is not able to scroll horizontally due to the focus of the input, which always gets passed onto the vertical scrollers.

How do I make both the horizontal and the vertical divs scrollable for iOS, so it works the same way as it does in Chrome?

like image 480
Frederik Witte Avatar asked Mar 11 '16 08:03

Frederik Witte


People also ask

How do I enable horizontal scrolling in a div?

Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.

How do I make my scroll horizontal?

Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.

How do I make a horizontal scrolling image in HTML?

The scrolling images were acheived using the HTML <marquee> tag. Using this tag, you can give your images a horizontal scroll (from right to left, left to right) or a vertical scroll (top to bottom, or bottom to top). Note that the <marquee> tag isn't an offical HTML tag (but it is recognized by most modern browsers).


2 Answers

I think you'd be better off taking the carousel approach where you'd be moving a container when swiping, rather than user the "native" scroll behaviour.

That way you'll be able to slide your DIVs left and right with JS, and scroll up and down using regular scrolling.

like image 92
justinledouxweb Avatar answered Sep 26 '22 00:09

justinledouxweb


You need to replace all overflow-*AXIS* to simple overflow auto:

<div style="overflow: auto; white-space: nowrap; width: 100%; height: 100%; position: relative; background-color: black;">
     <div style="width: 100%; height: 100%; left: 0%; top: 0px; margin: 0px; position: absolute; display: inline-block; background-color: green;">
        <div style="width: 100%; height: 100%; overflow: auto;">
           <div style="width: 100%; height: 200%;"></div>
        </div>
     </div>
     <div style="width: 100%; height: 100%; left: 100%; top: 0px; margin: 0px; position: absolute; display: inline-block; background-color: blue;">
        <div style="width: 100%; height: 100%; overflow: auto;">
           <div style="width: 100%; height: 200%;"></div>
        </div>
     </div>
  </div>
like image 38
Undefitied Avatar answered Sep 27 '22 00:09

Undefitied