响应式导航(Responsive Nav)插件

响应式导航(Responsive Nav)插件
响应式导航(Responsive Nav)是一个轻量级JS插件,他的体积很小压缩之后仅有1.7KB,它不依赖于任何第三方工具库,并且支持触屏操作。调整当前窗口大小即可看到惊艳的效果,能帮你创建针对小屏幕的可切换式导航。

入门指南

Responsive Nav特性

  1. 压缩后仅1.7 KB。
  2. 不依赖任何第三方工具库。
  3. 支持CSS3过渡(transitions)效果、触屏事件,并且只需要很简单的HTML代码结构。
  4. 移除了物理触屏事件和系统点击事件之间的300ms延时。
  5. 可以将CSS3过渡(transitions)效果与height: auto一同使用。
  6. 从设计此插件之初就将可访问性考虑在内,它能支持屏幕阅读器,并且能在禁用JavaScript的浏览器上工作。
  7. 可以在所有主流桌面、移动设备浏览器上工作,包括IE6+。

引入文件

<!-- 引入这些文件至 <head> 中 -->
<link rel="stylesheet" href="responsive-nav.css">
<script src="responsive-nav.js"></script>添加标签<div id="nav">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Projects</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</div>

启动此插件

<!-- 将下面这段代码放置在 </body> 之前 -->
<script>
  var navigation = responsiveNav("#nav");
</script>

调整参数

var navigation = responsiveNav("#nav", { // Selector: The ID of the wrapper
  animate: true, // Boolean: 是否启动CSS过渡效果(transitions), true 或 false
  transition: 400, // Integer: 过渡效果的执行速度,以毫秒(millisecond)为单位
  label: "Menu", // String: Label for the navigation toggle
  insert: "after", // String: Insert the toggle before or after the navigation
  customToggle: "", // Selector: Specify the ID of a custom toggle
  openPos: "relative", // String: Position of the opened nav, relative or static
  jsClass: "js", // String: 'JS enabled' class which is added to <html> el
  debug: false, // Boolean: Log debug messages to console, true 或 false
  init: function(){}, // Function: Init callback
  open: function(){}, // Function: Open callback
  close: function(){} // Function: Close callback
});

可调用的方法

// 销毁插件
navigation.destroy();

// Toggle
navigation.toggle();

the end