【发布时间】:2013-08-12 20:11:02
【问题描述】:
我注意到,即使在 iOS 上,Bootstrap 的 navbar 也能以 fixed 定位保持在窗口的顶部。尽管我认为如果不重新实现 iOS 滚动就不可能做到这一点?
我想知道这是如何工作的,以及我如何根据自己的观点来做到这一点?我尝试过的任何方法似乎都不起作用 - div 在滚动时未对齐,并且仅在滚动结束后才跳转到位置。
编辑:这是一个最小的(ish!)示例。看看在 iOS 上fixedThing 是如何在你向下滚动时跳起来的。也许这与与navbar 的交互有关?
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
.fixedThing {
position: fixed;
width: 100%;
height: 100%;
background: red;
opacity: 0.5;
}
.navbar {
width: 100%;
}
</style>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
</div>
<div class="fixedThing"></div>
<p>...insert lots of page content so it scrolls ...</p>
</body>
</html>
【问题讨论】:
-
你运行的是什么版本的 iOS?
-
我的物理 iPhone 上的 6.x 和 iPhone 模拟器上的各种(通常是 5.x)。
标签: html css twitter-bootstrap mobile-safari css-position