響應(yīng)式導(dǎo)航(Responsive Nav)是一個很小的JavaScript插件疙描,壓縮之后僅有1.7KB掷空,能幫你創(chuàng)建針對小屏幕的可切換式導(dǎo)航乃正。它支持觸屏事件和CSS3過渡(transitions)效果谦铃,具有非常好的性能啦辐。他還能支持從height: 0 到 height: auto過渡卓嫂,這是在CSS3過渡效果中很不容易實現(xiàn)的慷暂。
響應(yīng)式導(dǎo)航優(yōu)點:
壓縮后僅1.7 KB。
不依賴任何第三方工具庫晨雳。
支持CSS3過渡(transitions)效果行瑞、觸屏事件,并且只需要很簡單的HTML代碼結(jié)構(gòu)餐禁。
移除了物理觸屏事件和系統(tǒng)點擊事件之間的300ms延時血久。
可以將CSS3過渡(transitions)效果與height: auto一同使用。
從設(shè)計此插件之初就將可訪問性考慮在內(nèi)帮非,它能支持屏幕閱讀器氧吐,并且能 在禁用JavaScript的瀏覽器上工作。
可以在所有主流桌面末盔、移動設(shè)備瀏覽器上工作筑舅,包括IE6+。
操作:
(1)引入文件
<link rel="stylesheet" href="responsive-nav.css">
<script src="responsive-nav.js"></script>
(2)添加標(biāo)簽
<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>
(3)啟動此插件
<!-- 將下面這段代碼放置在 </body> 之前 -->
<script>
var navigation = responsiveNav("#nav");
</script>
(4)調(diào)整參數(shù)
var navigation = responsiveNav("#nav", { // Selector: The ID of the wrapper
animate: true, // Boolean: 是否啟動CSS過渡效果(transitions)陨舱, true 或 false
transition: 400, // Integer: 過渡效果的執(zhí)行速度翠拣,以毫秒(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
});
(5)可調(diào)用的方法
// 銷毀插件
navigation.destroy();
// Toggle
navigation.toggle();