当您向下滚动页面时,使用“navbar”和“navbar-fixed-top”类会在页面顶部浮动导航栏。这似乎不适用于移动/ ipad浏览器。我们为什么以及如何让它们在移动浏览器上浮动。在ipad(safari,chrome)Android(firefox)Windows Phone(IE)上试过这个。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<span class="brand"><img title="Logo" alt="Logo" src="static/images/iu_logo.gif" /></span>
<div class="nav-collapse">
<ul class="nav">
<li class="active">
<a id="homeLink" href="#">Home</a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" id="newsLink" href="#">News</a>
<ul class="dropdown-menu">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li class="divider"></li>
<li><a href="#">Another link</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
<li id="loginLink"><a href="#" id="loginButton">Login</a></li>
</ul>
</div>
</div>
</div>
50 lines of text (just to have the page scrollable)
</body>
</html>
我在head标签中有以下行,以便为移动设备启用bootstrap响应。
<meta name="viewport" content="width=device-width, initial-scale=1.0">
任何建议
答案 0 :(得分:12)
我遇到了同样的问题,我对其他框架进行了一些调查。 由于JQuery Mobile在固定导航栏中正常工作,问题必须只在Bootstrap'侧,实际上他们是故意禁用它(更多细节如下)。
您可以通过添加内联样式来尝试。
<div class="navbar navbar-fixed-top navbar-inverse" style="position:fixed">
当然,您需要相应地调整导航栏样式。 我做了如下:
/* Override Bootstrap Responsive CSS fixed navbar */
@media (max-width: 979px) {
.navbar-fixed-top,
.navbar-fixed-bottom {
position: fixed;
margin-left: 0px;
margin-right: 0px;
}
}
我在响应式CSS后添加了这个。
我尝试了各种设备......一款低成本的Android平板电脑,我的高端Android手机。 我从没试过iOS。 最令人惊奇的是它在Firefox for Android上运行非常流畅。
这是关于github的问题之一,由Bootstrap的作者回复,并引用了JQM采用的详细解决方案:https://github.com/twitter/bootstrap/issues/1617
答案 1 :(得分:5)
Bootstrap在小屏幕中不使用固定导航栏,因为它在移动设备中不能正常工作。在bootstrap-responsive.css
中,您可以找到:
@media (max-width: 979px) {
...
.navbar-fixed-top,
.navbar-fixed-bottom {
position: static;
}
...
}
尝试删除它或只是不加载bootstrap-responsive.css
样式表,并检查移动设备上会发生什么,然后你会发现它是必要的:)在我的低成本Android移动固定元素没有修复滚动。遍历所有可见屏幕。滚动完成后,浏览器重新计算固定元素的位置,导航栏跳转到正确的位置。