html - '溢出-x : scroll' inside a fixed div prevents vertical scrolling on ios

标签 html ios css

似乎如果你有一个带水平滚动的 div,在一个定位固定的 div 内,它会阻止 IOS 上的垂直滚动。 I.E - 如果我通过将手指放在水平滚动的 div 上开始滚动,然后尝试垂直滚动,什么也没有发生。

在我同事的 Andriod 设备上似乎没问题。

我已经创建了一个测试用例,在这里演示了这个问题:

http://jsbin.com/jikatugeli/

这是html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  some content underneath
  <div class="pop-up">
    <p>I'm some other content</p>
    <div class="scrollable">
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
      <div class="item">hi</div>
    </div>
    <div class="somemoretext">
      hello there, I am some text to make things scrollable
    </div>
  </div>
</body>
</html>

这是CSS

p {
  font-size:22px;
}

.item {
  display:inline-block;
  width:80px;
    height:60px;
  font-size:78px;
}

.scrollable {
  width:350px;
  white-space: nowrap;
  overflow-x:scroll;
  overflow-y:hidden;
}

.pop-up {
  position:fixed;
  height:300px;
  background:red;
  border: 1px solid #000;
  width:100%;
  top:0;
  overflow-y:scroll;
  z-index:9999;
}

.somemoretext {
  padding-top:600px;
}

感谢您的帮助。

最佳答案

下面的 css 解决了你的问题

html,body{height:100%}
body{background:red}
p {
  font-size:22px;
}

.item {
  display:inline-block;
  width:80px;
    height:60px;
  font-size:78px;
}

.scrollable {
  width:350px;
  white-space: nowrap;
  overflow-x:scroll;
  overflow-y:hidde;
  position: relative;
  -webkit-transform: translateZ(0);
}

.pop-up {
  position:fixed;
  height:300px;
  background:blue;
  border: 1px solid #000;
  width:100%;
  top:0;
  overflow-y:scroll;
  z-index:9999;
  -webkit-overflow-scrolling: touch;
}

.somemoretext {
  padding-top:600px;
}

包含 -webkit- 的行是在 Safari 中实现滚动的关键。
在 .pop-up DIV 中,您需要 overflow-y: scroll 和 –webkit-overflow-scrolling: touch 来强制滚动。在 .scrollable 你需要 –webkit-transform: tranzlateZ(0);上下移动实际的 html 内容,否则 DIV 将滚动但不会显示溢出的内容。

关于html - '溢出-x : scroll' inside a fixed div prevents vertical scrolling on ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41681251/

相关文章:

html - 从 html 运行 shell 脚本

ios - 将 .cer 转换为 .p12

ios - 如何使 UILocalNotification 在 swift 中不重复?

css - IE8 和其他所有内容之间的 CSS 旋转的一致来源?

html - 当您缩小浏览器时,页眉的背景图片不会占据全宽

html - 在 <td></td> 中间制作文本并在 HTML 中溢出它们

html - the_content() wordpress 创建不需要的顶部空间

php - 无法将我当前的菜单转换为 Bootstrap 菜单

ios - Storyboard中带有自定义字体的属性字符串无法正确加载

html - 列设置为 100% 高度的响应式 CSS