Foundation 中文手册

浏览24121
更新时间2022-04-14

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 指定了导航条距离头部的像素值 尝试一下


相关视频

更多

免费

前端入门_HTML5
初级前端入门_HTML5

64.8万次学习

收藏

免费

30分钟学会网站布局
初级30分钟学会网站布局

24.6万次学习

收藏

免费

CSS视频教程-玉女心经版
初级CSS视频教程-玉女心经版

41.1万次学习

收藏

免费

JavaScript极速入门_玉女心经系列
初级JavaScript极速入门_玉女心经系列

76.4万次学习

收藏

精品课程

更多
前端入门_HTML5
前端入门_HTML5

共29课时

64.9万人学习

CSS视频教程-玉女心经版
CSS视频教程-玉女心经版

共25课时

41.2万人学习

JavaScript极速入门_玉女心经系列
JavaScript极速入门_玉女心经系列

共43课时

76.6万人学习

独孤九贱(1)_HTML5视频教程
独孤九贱(1)_HTML5视频教程

共25课时

64.1万人学习

独孤九贱(2)_CSS视频教程
独孤九贱(2)_CSS视频教程

共22课时

24.3万人学习

独孤九贱(3)_JavaScript视频教程
独孤九贱(3)_JavaScript视频教程

共28课时

36.2万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时

133.1万人学习

热门下载

更多
phpStudy 2018最新版
phpStudy 2018最新版

集成PHP7,16种组合,超全大合集

下载

VC9 32位
VC9 32位

VC9 32位 phpstudy集成安装环境运行库

下载

VC11 32位
VC11 32位

VC11 32位 phpstudy集成安装环境运行库​

下载

php程序员工具箱完整版
php程序员工具箱完整版

程序员工具箱 v1.0 php集成环境

下载

VC14 32位
VC14 32位

VC14 32位 phpstudy安装环境运行库

下载

SublimeText3汉化版
SublimeText3汉化版

中文版,非常好用

下载

Notepad++ Windows版
Notepad++ Windows版

Notepad++ 8.9.7 Windows版官方安装包,适合 Windows 用户进行代码编辑、文本处理、语法高亮和插件扩展配置。

下载