Foundation 中文手册
/ Foundation Magellan
Foundation Magellan
Foundation 麦哲伦(Magellan)导航
如何创建麦哲伦导航
麦哲伦导航就是一个导航索引,创建方式如下:
实例
<!DOCTYPE html>
<html>
<head>
<title>Foundation 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
<script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
</head>
<body style="height:1500px;padding:20px;">
<h2>Magellan</h2>
<h4 class="subheader">麦哲伦导航就是一个导航索引,位置是固定的,会根据用户滚动当前展示的内容自动切换导航栏上的导航项:</h4>
<hr>
<div data-magellan-expedition="fixed">
<dl class="sub-nav">
<dd data-magellan-arrival="page1"><a href="#page1">Page 1</a></dd>
<dd data-magellan-arrival="page2"><a href="#page2">Page 2</a></dd>
</dl>
</div>
<hr>
<div style="height:200px;background-color:#1abc9c;color:white;">
<h3 data-magellan-destination="page1">页面 1</h3>
<a name="page1"></a>
<p>滚动屏幕,查看导航栏上的变化。</p>
</div>
<h3 data-magellan-destination="page2">页面 2</h3>
<a name="page2"></a>
<p>滚动屏幕,查看导航栏上的变化。并尝试向上滚动。</p>
<!-- 初始化 Foundation JS -->
<script>
$(document).ready(function() {
$(document).foundation();
})
</script>
</body>
</html>运行实例 »
点击 "运行实例" 按钮查看在线实例
实例解析
在 <div> 元素上添加 data-magellan-expedition="fixed" 属性来创建麦哲伦导航。
然后在 <dd> 或 <li> 上添加 data-magellan-arrival="value" 属性,后面添加一个与该属性值一样的链接(page1)。
使用 data-magellan-destination="value" 属性来控制麦哲伦导航的目标, 后面紧跟的 <a> 元素添加 name="value" 属性。两个属性的值必须与 data-magellan-arrival 的值一致 (page1)。
最后,初始化 Foundation JS ,用户在滚动页面时导航就会根据当前显示的内容自动切换。
麦哲伦导航头部工具条
麦哲伦导航使用头部工具条实例:
实例
<!DOCTYPE html>
<html>
<head>
<title>Foundation 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
<script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
</head>
<body>
<div data-magellan-expedition="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="#">WebSiteName</a></h1>
</li>
<!-- Collapsible Button on small screens: remove the .menu-icon class to get rid of icon.
Remove the "Menu" text if you only want to show the icon -->
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<ul class="left">
<li data-magellan-arrival="page1"><a href="#page1">Page 1</a></li>
<li data-magellan-arrival="page2"><a href="#page2">Page 2</a></li>
</ul>
</section>
</nav>
</div>
<div style="padding:20px;height:1500px;">
<h3>Magellan 头部导航实例</h3>
<p>向下滚动页面查看效果。</p>
<div style="height:200px;background-color:#1abc9c;color:white;">
<h3 data-magellan-destination="page1">Page1</h3>
<a name="page1"></a>
<p>滚动屏幕,查看导航栏上的变化。</p>
</div>
<h3 data-magellan-destination="page2">Page2</h3>
<a name="page2"></a>
<p>滚动屏幕,查看导航栏上的变化。并尝试向上滚动。</p>
</div>
<!-- 初始化 Foundation JS -->
<script>
$(document).ready(function() {
$(document).foundation();
})
</script>
</body>
</html>运行实例 »
点击 "运行实例" 按钮查看在线实例
麦哲伦导航内边距
默认情况下,麦哲伦导航的 <div> 元素有 10px 的内边距。可以使用 CSS 移除它:
实例
<!DOCTYPE html>
<html>
<head>
<title>Foundation 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
<script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
<script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
<style>
[data-magellan-expedition], [data-magellan-expedition-clone] {
padding: 0;
}
</style>
</head>
<body>
<div data-magellan-expedition="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="#">WebSiteName</a></h1>
</li>
<!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。
如果需要只显示图片,可以删除 "Menu" 文本 -->
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<ul class="left">
<li data-magellan-arrival="page1"><a href="#page1">Page 1</a></li>
<li data-magellan-arrival="page2"><a href="#page2">Page 2</a></li>
</ul>
</section>
</nav>
</div>
<div style="padding:20px;height:1500px;">
<h3>Magellan 头部导航实例</h3>
<p>向下滚动页面查看效果。</p>
<div style="height:200px;background-color:#1abc9c;color:white;">
<h3 data-magellan-destination="page1">Page1</h3>
<a name="page1"></a>
<p>滚动屏幕,查看导航栏上的变化。</p>
</div>
<h3 data-magellan-destination="page2">Page2</h3>
<a name="page2"></a>
<p>滚动屏幕,查看导航栏上的变化。并尝试向上滚动。</p>
</div>
<!-- 初始化 Foundation JS -->
<script>
$(document).ready(function() {
$(document).foundation();
})
</script>
</body>
</html>运行实例 »
点击 "运行实例" 按钮查看在线实例
麦哲伦导航选项
使用 data-options 属性修改麦哲伦导航的设置, 例如 <div data-magellan-expedition="fixed" data-options="destination_threshold:60">:
| 名称 | 类型 | 默认 | 描述 | 实例 |
|---|---|---|---|---|
| active_class | string | active | 指定激活链接的类 | 尝试一下 |
| threshold | number | 0 | 指定导航在什么时候需要固定位置。会根据滚动条滚动计算,默认为 0 (auto)。 | 尝试一下 |
| destination_threshold | number | 20 | 设该值设定了导航链接显示为激活(蓝色背景)时导航列表距离顶部的值。 | 尝试一下 |
| fixed_top | number | 0 | 指定了导航条距离头部的像素值 | 尝试一下 |
