【问题标题】:Modal (fixed element) unscrollable after input focus in iOS safari在 iOS Safari 中输入焦点后无法滚动的模式(固定元素)
【发布时间】:2015-10-29 16:04:55
【问题描述】:
【问题讨论】:
标签:
html
css
twitter-bootstrap
twitter-bootstrap-3
【解决方案1】:
添加这个css代码:
html, body {
overflow-y: scroll; /* has to be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
【解决方案2】:
将此添加到 bootstrap.css 中的 .modal-open(overflow:hidden; - 已经在我的里面了)。
.modal-open {
position: fixed;
overflow: hidden;
left:0;
right:0;
}
这是我正在使用的临时解决方案。它使滚动再次起作用,但是当模式关闭时,主页会滚动回顶部。比以前更好,但不是真正的解决方案。我得到了解决方案:
@Eru Penkman -
Bootstrap 3 modal with long form on iPhone doesn't scroll if you touch input field
他还补充说:
.modal{
-webkit-overflow-scrolling: auto;
}
但这并没有解决 scroll back to top 问题并导致滚动出现故障,所以我也把它放回去了:
.modal{
-webkit-overflow-scrolling: touch;
}
希望这会有所帮助。如果您找到解决所有问题的解决方案,请告诉我... :)
【解决方案3】:
超级老线程,但我刚刚遇到这个问题,所以这是我的解决方案。我有 javascript 中引用的所有元素。当用户输入输入时,将填充搜索结果列表。添加这些结果,再加上 iOS 在打开键盘时移动物体的行为会导致错误,一旦键盘消失,保存输入和结果的 div 的容器将无法滚动。
// results is a div holding the results.
// As soon as the search returns and the results are
// added (even before the keyboard is gone) i run the
// code below and once the keyboard is gone things scroll
// properly. It's basically a hack to get the browser to
// recalculate positioning and rendering. class 'absolute'
// just sets the position to absolute from it's default 'relative'.
results.addClass('absolute');
// Force browser to assume there's upcoming rendering to do
results.element.clientHeight;
// remove class
results.removeClass('absolute');
似乎无论对哪个元素、结果容器或父元素执行此操作,它都可能适用于该层次结构中的其他元素。