Giter Site home page Giter Site logo

james-yong / navbar.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thednp/navbar

0.0 1.0 0.0 1.14 MB

Modern Navigation Component

Home Page: http://thednp.github.io/navbar.js/

License: MIT License

JavaScript 32.74% TypeScript 0.08% SCSS 67.17%

navbar.js's Introduction

Navbar.js - Modern Navigation Component

The mobile first menu navigation for today's modern web, developed with ES6+ JavaScript, TypeScript definitions and packed with lots of features.

NPM Version NPM Downloads jsDeliver

Demo

Download the package and check the demo folder, or check it online here.

Navbar.js Highlights

  • Mobile First Design
  • Accessibility Focus
  • ES6+ sources with TypeScript definitions and powerful build tools
  • SCSS sources with powerful mixins and advanced inheritance and automation functionality
  • very light footprint, 5kb in size when minified
  • 3 sets of positions top (main), left or right
  • provides a set of options for JavaScript initialization
  • DATA API allows you to automatically initiate without JS invocation
  • modern browsers supported and semi-modern alike with a special polyfill for IE10+ provided

How It Works

On mobile

  • uses the default events behavior, it requires some elements to click on
  • shows the <button class="navbar-toggle"> element for element visibility toggle
  • menu items have a <button class="subnav-toggle"> element that enables visibility of the submenus
  • makes use of the open-mobile class to toggle submenus via the click handler

On the desktop

  • hides mobile specific elements and changes event behavior to mouse hover
  • opens submenus on mouseenter, by adding open and open-position classes to the menu item, in rapid succession
  • hides submenus on mouseleave, by removing the above classes in a delayed succesion

On both mobile and desktop, Navbar.js allows for full keyboard navigation via the TAB and SPACE keys. In addition, directional arrows provide navigation on desktop with RTL support.

NPM

You can install this through NPM:

$ npm install navbar.js

Browser Usage

Download the latest package. unpack and inspect the contents. You need to copy the navbar.js and navbar.css or their minified variations to your app assets folders as follows. Link the required CSS in your document <head> tag

<link href="../assets/css/navbar.css" rel="stylesheet">

Link the required JS in your document <body> tag, though it should work in the <head> as well

<script src="../assets/js/navbar.js"></script>

Initiate the function for your elements at the end of your <body> tag

<script>
var myMenu = new Navbar('selector');
</script>

To use the DATA-API, you need to provide the data-function="navbar" attribute to your navbar, like so:

<nav class="navbar" data-function="navbar">
  <a href="#" title="App Name">Brand Name</a>
  <button class="navbar-toggle">
    <i class="menu-icon"></i>
  </button>
  <div>
    <ul class="nav">
      <li><a href="#">Link Title</a></li>
      <li><a href="#">Another Link Title</a></li>
    </ul>
  </div>
</nav>

Alternatively you can use only the menu itself and use the specific attribute:

<div class="sidebar">
  <ul class="nav" data-function="navbar">
    <li><a href="#">Link Title</a></li>
    <li><a href="#">Another Link</a></li>
  </ul>
</div>

Other initialization and markup options apply, explained in the demo.

ES6+

import Navbar from 'navbar.js'

let myNav = new Navbar('#myNav')

Node

// get and store it
var Navbar = require("navbar.js");

// initialize it
var myMenu = new Navbar('#myNav');

License

MIT License

navbar.js's People

Contributors

thednp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.