Git Product home page Git Product logo

somewebmedia / hc-offcanvas-nav Goto Github PK

View Code? Open in Web Editor NEW
336.0 24.0 82.0 3.44 MB

JavaScript library for creating toggled off-canvas multi-level navigations, allowing endless nesting of submenu elements, supporting swipe gestures, keyboard interactions and ARIA attributes.

Home Page: https://somewebmedia.github.io/hc-offcanvas-nav/

License: MIT License

JavaScript 73.59% SCSS 26.41%
navigation menu mobile nav mobile-navigation hamburger hamburger-menu jquery jquery-plugin swipe-menu

hc-offcanvas-nav's Introduction

HC Off-canvas Nav

Version Downloads

JavaScript library for creating off-canvas multi-level navigations, using ARIA. Dependency free, but also works as a jQuery plugin. Demo

Features

  • Multi-level menu support
  • Endless nesting of navigation elements
  • Custom content inside menu items
  • Push/Slide DOM elements of choice
  • Touch swipe guestures
  • Different navigation positions
  • No dependencies
  • Flexible, simple markup
  • A number of exposed Options, Methods and Events
  • 2 Themes
  • Cross-browser compatibility
  • Full ARIA keyboard support
    • It relies on ARIA Design pattern for Dialogs
    • The tab key loops through all of the keyboard focusable items within the offcanvas navigation
    • You can close it using Esc

Quick start

Install

This package can be installed with:

  • npm: npm install --save hc-offcanvas-nav

Or download the latest release.

Including HC Off-canvas Nav

Script and Css tag

<link rel="stylesheet" href="/path/to/hc-offcanvas-nav.css">

<script src="/path/to/hc-offcanvas-nav.js"></script>

Webpack/Browserify

In the script, including HC Off-canvas Nav will usually look like this:

const hcOffcanvasNav = require('hc-offcanvas-nav');

Babel

import hcOffcanvasNav from 'hc-offcanvas-nav';

AMD (Asynchronous Module Definition)

If using AMD, the module will be automatically defined as hcOffcanvasNav.

SCSS

@import 'hc-offcanvas-nav/src/scss/core';
@import 'hc-offcanvas-nav/src/scss/toggle';
@import 'hc-offcanvas-nav/src/scss/theme-default';

Usage

Be sure to call the Nav once your menu element is available in the DOM.

Vanilla JS

document.addEventListener('DOMContentLoaded', function() {

  var Nav = new hcOffcanvasNav('#main-nav', {
    disableAt: 1024,
    customToggle: '.toggle',
    navTitle: 'All Categories',
    levelTitles: true,
    levelTitleAsBack: true
  });

});

jQuery

jQuery(document).ready(function($) {

  $('#main-nav').hcOffcanvasNav({
    disableAt: 1024,
    customToggle: $('.toggle'),
    navTitle: 'All Categories',
    levelTitles: true,
    levelTitleAsBack: true
  });

});

For HC Off-canvas Nav to work as a jQuery plugin, jQuery has to be a property of global window object, so be careful when using it in combination with Babel/Webpack/Browserify and jQuery.

Example HTML menu structure

<nav id="main-nav">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li>
      <a href="#">Services</a>
      <ul>
        <li>
          <a href="#">Hosting</a>
          <ul>
            <li><a href="#">Private Server</a></li>
            <li><a href="#">Managed Hosting</a></li>
          </ul>
        </li>
        <li><a href="#">Domains</a></li>
        <li><a href="#">Websites</a></li>
      </ul>
    </li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

Themes

HC Off-canvas Nav currently has 2 themes, the default and Carbon. To use Carbon theme simply call the Carbon theme css instead of the default one:

<link rel="stylesheet" href="/path/to/hc-offcanvas-nav.carbon.css">

Or if compiling the SCSS from the src dir, @include it from there:

@import 'hc-offcanvas-nav/src/scss/core';
@import 'hc-offcanvas-nav/src/scss/toggle';
@import 'hc-offcanvas-nav/src/scss/theme-carbon';

Options

Property Default Type Description
width 280 int / str Width of the nav. Used for left and right positions.
height 'auto' int / str Height of the nav. Used for top and bottom positions.
disableAt false int / bool Resolution above which to hide the offcanvas menu, and show the original.
pushContent null str / Element obj Content element (string selector or HTML Element object) that will be pushed when the navigation is open.
expanded false bool Initialize menu in expanded mode. It won't push content.
position 'left' str Position on which the menu will open. Available options: 'left', 'right', 'top' and 'bottom'.
swipeGestures true bool Enable open/close swipe gestures like in native apps. Works only for left and right positions.
levelOpen 'overlap' str Submenu levels open effect. Available options: 'overlap', 'expand', 'none' or false.
levelSpacing 40 int If levels are overlaped, this is the spacing between them, if they are expanding or always open, this is the text indent of the submenus.
levelTitles true bool Show titles for submenus, which is the parent item name. Works only for overlaped levels.
navTitle null str / Element obj Main navigation (first level) title. Can also be HTML object like an image (logo).
navClass '' str Custom navigation class.
disableBody true bool Disable body scroll when navigation is open.
closeOpenLevels true bool Should all open sub levels be closed when the nav closes.
closeActiveLevel false bool Should initially active sub level (see data-nav-active) be cleared when the nav closes.
closeOnClick true bool Close the navigation when links are clicked.
closeOnEsc true bool Close the navigation on Esc button.
customToggle null str / Element obj Custom navigation toggle element.
activeToggleClass null str Custom active toggle class.
insertClose true bool / int Insert navigation close button. You can also use an integer representing 0-based index that will be the position of the button in the list. Negative numbers are also supported.
insertBack true bool / int Insert back buttons to submenus. You can also use an integer representing 0-based index that will be the position of the button in the list. Negative numbers are also supported. Works only for overlaped levels.
labelClose '' str Label for the close button.
labelBack 'Back' str Label for the back buttons.
levelTitleAsBack true bool Use level titles as back labels.
rtl false bool Set the content direction to right-to-left.
bodyInsert 'prepend' str Choose to prepend or append navigation to body.
keepClasses true bool Should original menus and their items classes be preserved or excluded.
removeOriginalNav false bool Remove original menu from the DOM. Don't use this if planning to update the nav!
ariaLabels {...} obj Labels for the ARIA attributes. If using HC Off-canvas Nav in different language than English, you should translate all the properties. See the next section.

ARIA labels for the aria-label attributes on specific elements which will provide a text alternative to the elements that have no visible text on the screen.

ariaLabels: {
  open:     'Open Menu',
  close:    'Close Menu',
  submenu:  'Submenu'
}

Methods

The HC Off-canvas Nav API offers a couple of methods to control the offcanvas and are publicly available to all active instances.

Vanilla JS

var Nav = new hcOffcanvasNav();

jQuery

var $nav = $('#main-nav').hcOffcanvasNav();
var Nav = $nav.data('hcOffcanvasNav');

.getSettings()

Returns current settings.

var currentSettings = Nav.getSettings();

.isOpen()

Checks if the nav is open, and returns boolean.

if (Nav.isOpen()) {
  // do something
}

.update(options, updateDOM)

Updates just the specified settings with the new ones.

Nav.update({
  disableAt: 1024,
  navTitle: 'All pages'
});

Updates nav DOM. You don't have to pass empty settings object, the method is smart. Use this when original nav has been altered.

Nav.update(true);

Updates both settings and nav DOM. Use this when original nav was changed and you also want to update some specific settings.

Nav.update({
  disableAt: 1024,
  navTitle: 'All pages'
}, true);

.open(level, index)

Opens the nav if closed.

Nav.open();

Open the nav and also a specific sub menu. Each level sub menu has its own index that is relative to that level, not the parent menu.

Nav.open(2, 1);

Above code will open the nested menu in the example structure bellow:

<nav>
  <ul><!-- Level: 0 -->
    <li></li>
    <li>
      <ul><!-- Level: 1, Index 0 -->
        <li>
          <ul><!-- Level: 2, Index: 0 -->
            <li></li>
            <li></li>
          </ul>
        </li>
        <li>

          <ul><!-- Level: 2, Index: 1 -->
            <li></li>
            <li></li>
          </ul>

        </li>
      </ul>
    </li>
    <li></li>
    <li>
      <ul><!-- Level: 1, Index 1 -->
        <li>
          <ul><!-- Level: 2, Index: 2 -->
            <li></li>
            <li></li>
          </ul>
        </li>
        <li></li>
      </ul>
    </li>
  </ul>
</nav>

.close()

Closes the nav if open.

Nav.close();

.toggle()

Toggles (open/close) the nav.

Nav.toggle();

.on(eventName, cb)

Attach Event listener to the nav.

Nav.on('close', function() {
  // do something on close
});

.off(eventName, cb)

Remove Event listener from the nav.

// remove specific function
Nav.off('close', onCloseFunction);

// remove all event listeners
Nav.off('close');

Events

Event Description
open Triggers each time after nav is opened.
open.level Triggers each time after any level is opened.
close Triggers each time after nav is closed.
close.once Triggers only the first time after nav is closed, and than it detaches itself.
close.level Triggers each time after any level is closed.
toggle Triggers each time nav is triggered to be opened or closed.

All events return Event object as first argument, and the plugin Settings object as second argument.

  • open.level and close.level return the newly opened level and index under the Event.data property.
  • toggle event returns the action under the Event.data property.

Open and close events are triggered after the nav animation is over, whie toggle event gets triggered imediatelly.

Examples:

// change nav open position after each close
Nav.on('close', function(e, settings) {
  Nav.update({
    position: settings.position === 'left' ? 'right' : 'left'
  });
});

// will change nav open position only once
Nav.on('close.once', function(e, settings) {
  Nav.update({
    position: settings.position === 'left' ? 'right' : 'left'
  });
});

Nav.on('open.level', (e, settings) => {
  localStorage.setItem('NavLevel', e.data.currentLevel);
  localStorage.setItem('NavIndex', e.data.currentIndex);
});

Nav.on('close.level', (e, settings) => {
  localStorage.setItem('NavLevel', e.data.currentLevel);
  localStorage.setItem('NavIndex', e.data.currentIndex);
});

Nav.on('toggle', (e, settings) => {
  if (e.data.action == 'open') {
    // do something when `open` action is triggered
  }
});

Data Attributes

Attr Accepts HTML Element Description
data-nav-active <ul>, <li> The next time nav opens it will open specified sub menu (or sub menu whose parent <li> element has the attribute). Works with expanded option.
data-nav-highlight <li> Highlight list item.
data-nav-custom-content <li> Attached on the list items. Will clone item's content as is.
data-nav-close bool <a> Attached on the item links. Tells the nav if it needs to be closed on click or not.
<nav id="main-nav">
  <ul>
    <li data-nav-custom-content>
      <div>Some custom content</div>
    </li>
    <li data-nav-highlight><a href="#">Home</a></li>
    <li data-nav-active>
      <a href="#">About</a>
      <ul data-nav-active><!-- or active attribute can be here -->
        <li><a href="#">Team</a></li>
        <li><a href="#">Project</a></li>
        <li><a href="#">Services</a></li>
      </ul>
    </li>
    <li><a href="#">Contact</a></li>
    <li><a data-nav-close="false" href="#">Add Page</a></li>
  </ul>
</nav>

WordPress data attributes integration

If you want to make your WordPress theme nav data ready, just place this code to your functions.php file and it should work out of the box. Do not assign this custom Walker to your wp_nav_menu arguments! And don't worry if you already use your own custom Walker, this code will take care of everything.

/*
 * Adds menu data support for HC Off-canvas Nav
 */

$hc_nav_menu_walker;

class HC_Walker_Nav_Menu extends Walker_Nav_Menu {

  public function start_lvl(&$output, $depth = 0, $args = array()) {
    global $hc_nav_menu_walker;
    $hc_nav_menu_walker->start_lvl($output, $depth, $args);
  }

  public function end_lvl(&$output, $depth = 0, $args = array()) {
    global $hc_nav_menu_walker;
    $hc_nav_menu_walker->end_lvl($output, $depth, $args);
  }

  public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
    global $hc_nav_menu_walker;

    $item_output = '';

    $hc_nav_menu_walker->start_el($item_output, $item, $depth, $args, $id);

    if ($item->current_item_parent) {
      $item_output = preg_replace('/<li/', '<li data-nav-active', $item_output, 1);
    }

    if ($item->current) {
      $item_output = preg_replace('/<li/', '<li data-nav-highlight', $item_output, 1);
    }

    $output .= $item_output;
  }

  public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
    global $hc_nav_menu_walker;
    $hc_nav_menu_walker->end_el($output, $item, $depth, $args, $id);
  }
}

add_filter('wp_nav_menu_args', function($args) {
  global $hc_nav_menu_walker;

  if (!empty($args['walker'])) {
    $hc_nav_menu_walker = $args['walker'];
  }
  else {
    $hc_nav_menu_walker = new Walker_Nav_Menu();
  }

  $args['walker'] = new HC_Walker_Nav_Menu();

  return $args;
});

Dev Building

This package comes with Gulp. The following tasks are available:

  • default compiles the JS and SCSS into /dist and builds the demos into /docs.
  • demo executes default task and opens the demo html page.
  • watch watches source JS and SCSS files and builds them automatically whenever you save.

You can pass a --dev command if you don't want the compiled JS and Css to be minified.

License

The code and the documentation are released under the MIT License.

hc-offcanvas-nav's People

Contributors

4goodapp avatar sfritzsche avatar somewebmedia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hc-offcanvas-nav's Issues

(...).hcOffcanvasNav is not a function after Upgrade to 5.0.3

Hello i have a issue after update to 5.0.3 from webpack. (...).hcOffcanvasNav is not a function but it was working without problems before. There is something wrong in my app.js file? or did the alias change after update? I had to rollback to 4.2.6 meanwhile, i'll appreciate your help.

import $ from 'jquery';
import 'bootstrap';
import 'hc-offcanvas-nav';

$(function () {
        $('#main-nav').hcOffcanvasNav({
                disableAt: false,
                customToggle: $('.toggle'),
                levelSpacing: 40,
                navTitle: 'MENรš PRINCIPAL',
                labelClose: 'Cerrar',
                labelBack: 'Atrรกs',
                levelTitles: true,
                levelTitleAsBack: true,
                pushContent: '#container',
                insertClose: 2
        });
});

Column menu

How to make a menu in a column?
I have it in a line and a scroll bar below.

I set css in the settings
display: flex;
flex-direction: column;

That helped. But I would like to know if there is a more normal way to do this.

<div id="main-nav">
    <ul class="header__main_wrap">
       <li><a href="#" class="header__main--page">products</a></li>
       <li><a href="#" class="header__main--page">rooms</a></li>
       <li><a href="#" class="header__main--page">services</a></li>
       <li><a href="#" class="header__main--page">contacts</a></li>
     </ul>
 </div>
$(function() {
    jQuery(document).ready(function($) {
        $('#main-nav').hcOffcanvasNav({
            disableAt: 530,
            expanded: false,
            swipeGestures: true,
        });
    });
});

Look here

  1. https://photos.app.goo.gl/eukJGRNqdgY12y2x5
  2. https://photos.app.goo.gl/Hp8SBuTj8Q3bXMeF8

Change language from default options

Hello everyone! Hope you are doing ok!

I have a doubt. Can you edit the text from "close" and "back" default options in the nav? I'm asking this because I want to change them to another language.

cap-2020

Thanks for reading.

Keep selected item in nested menu

There is any way in which the menu can remember the selected menu within a nested menu? this is to avoid clicking multiple times when a menu within a menu has been selected.

Any plans to implement that?

Regards,

Jose.

Unable to open menu with swipe ?

Hi,
I have Android 10, with latest FF and Chrome today, the menu looks and feels amazing but I am unable to swipe and open the menu. I an only swipe and close the menu.
I would love to see the swipe open menu feature implemented in this repo.

Regards

Can't add a search box to the menu

I am trying to add a search box to the menu, however it does not show on the menu.

The code is completely removed by the plugin, how do i go about adding this?

This is the code i'm trying to add within the nav tag:

    <ul class="search">
        <li>
            <div class="input-group input-group-sm pt-1 w-75">
                <input type="text" class="form-control search-form-control" aria-label="Amount (to the nearest dollar)">
                <div class="input-group-append">
                    <span class="input-group-text search-icon">
                        <i class="fa fa-search" aria-hidden="true"></i>
                    </span>
                </div>
            </div>
        </li>
    </ul>

Ajax does not proceed?

Ajax does not proceed?
When I click first menu item in a menu created with hcOffcanvasNav, the Ajax result does not show.

I want to display it like this: when I click on the first li, the childs appears. And when those childs are clicked, the sub-childs appears.

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script src="hc-offcanvas-nav.js?ver=3.2.0"></script>

<div id="container">
  <div id="nav">
    <div id='state-list'>
      <div id='city-list'>
      </div>
    </div>
  </div>
</div>

<script>
var Nav;
Nav = $('#nav').hcOffcanvasNav({
  maxWidth: false,
  levelTitles: true,
  closeOnClick: false
});
</script>

<script src="jquery-3.2.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
  $('.state').click(function(e) {
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: "index.php",
      data: {
        activeMenu: this.id
      },
      success: function(data) {
        $("#state-list").html(data);
      }
    });
  });

  $('.city').click(function(e) {
    var teks = $(".linka").closest('li').attr('value');
    e.preventDefault();
    $.ajax({
      type: "POST",
      url: "index.php",
      data: {
        activeMenu: teks,
        activeSubMenu: this.id
      },
      success: function(data) {
        $("#city-list").html(data);
      }
    });
  });
});
</script>

Not Show

I need
show

@somewebmedia

Demo

Yesterday swiping from the side on the screen on mobile worked perfectly on the demo website. Today it seems to no longer be working. Tested multiple devices.

Brand logo on header

How to add brand logo on header. Icon in the right is enough to closing. How to add brand logo in left side.

Position fixed ignored on element when closing nav

When closing nav menu with a custom toggle placed in a top bar with position fixed cause the top bar to lose the fixed position when scrolling (so it is scrolled too when scrolling and doesn't remain visible to user on top).

This is caused from the translate3D property added to the toggle when opening/closing the nav (or a level). To fix this just remove the 3d property on nav close, with this edits the code works:

const setTransform = (() => {
        const transform = browserPrefix('transform');

        return ($el, val) => {
          if (transform) {
            const x = SETTINGS.side === 'left' ? val : -val;
            //if x is 0 remove the translate3d property
            if(x > 0)
              $el.css(transform, `translate3d(${x}px,0,0)`);
            else
              $el.css(transform, '');
          }
          else {
            $el.css(SETTINGS.side, val);
          }
        };
      })();

Issue with fixed header

First of all, thank you for this awesome menu!!!

I am having trouble getting it to work with a fixed header. When opening the menu, I have it set to push the content to the right. It works fine on first page load but if I scroll down and then open the menu, the fixed header disappears. I can't figure out what is causing this to happen. Hope you have a solution, thank you.

Menu icon position

I use the nav with Bootstrap, but when i size down the window the menu icon goes to the top of the page.
Can I place it in the same position where the nav tag is? (in my example, in the red border div).
Thank you.

Code:

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Google Font -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=EB+Garamond|Roboto">
<!-- HC Off-canvas CSS -->
<link rel="stylesheet" href="hc-offcanvas-nav.css">

<title>Page Title</title>
</head>
<body>
<div class="container">

<h1>Hello world!</h1>
<h2>Hello world!</h2>
<p>This is a paragraph.</p>

<table border="1" width="100%">
<tr>
<td>
Table Title
</td>
</tr>
<tr>
<td>
<div style="border:thin solid #88090B;">
<nav id="main-nav">

  <ul class="first-nav">
    <li class="cryptocurrency">
      <a href="#">Cryptocurrency</a>
      <ul>
        <li><a href="#">Bitcoin</a></li>
        <li><a href="#">Ethereum</a></li>
        <li><a href="#">NEO</a></li>
        <li><a href="#">ZCash</a></li>
        <li><a href="#">Dogecoin</a></li>
      </ul>
    </li>
  </ul>
 
  <ul class="second-nav">
    <li class="devices">
      <a>Devices</a>
      <ul>
        <li class="mobile">
          <a href="#">Mobile Phones</a>
          <ul>
            <li><a href="#">Super Smart Phone</a></li>
            <li><a href="#">Thin Magic Mobile</a></li>
            <li><a href="#">Performance Crusher</a></li>
            <li><a href="#">Futuristic Experience</a></li>
          </ul>
        </li>
        <li class="television">
          <a href="#">Televisions</a>
          <ul>
            <li><a href="#">Flat Superscreen</a></li>
            <li><a href="#">Gigantic LED</a></li>
            <li><a href="#">Power Eater</a></li>
            <li><a href="#">3D Experience</a></li>
            <li><a href="#">Classic Comfort</a></li>
          </ul>
        </li>
        <li class="camera">
          <a href="#">Cameras</a>
          <ul>
            <li><a href="#">Smart Shot</a></li>
            <li><a href="#">Power Shooter</a></li>
            <li><a href="#">Easy Photo Maker</a></li>
            <li><a href="#">Super Pixel</a></li>
          </ul>
        </li>
      </ul>
    </li>
    <li class="magazines">
      <a href="#">Magazines</a>
      <ul>
        <li><a href="#">National Geographic</a></li>
        <li><a href="#">Scientific American</a></li>
        <li><a href="#">The Spectator</a></li>
        <li><a href="#">The Rambler</a></li>
        <li><a href="#">Physics World</a></li>
        <li><a href="#">The New Scientist</a></li>
      </ul>
    </li>
    <li class="store">
      <a href="#">Store</a>
      <ul>
        <li>
          <a href="#">Clothes</a>
          <ul>
            <li>
              <a href="#">Women's Clothing</a>
              <ul>
                <li><a href="#">Tops</a></li>
                <li><a href="#">Dresses</a></li>
                <li><a href="#">Trousers</a></li>
                <li><a href="#">Shoes</a></li>
                <li><a href="#">Sale</a></li>
              </ul>
            </li>
            <li>
              <a href="#">Men's Clothing</a>
              <ul>
                <li><a href="#">Shirts</a></li>
                <li><a href="#">Trousers</a></li>
                <li><a href="#">Shoes</a></li>
                <li><a href="#">Sale</a></li>
              </ul>
            </li>
          </ul>
        </li>
        <li>
          <a href="#">Jewelry</a>
        </li>
        <li>
          <a href="#">Music</a>
        </li>
        <li>
          <a href="#">Grocery</a>
        </li>
      </ul>
    </li>
    <li class="collections"><a href="#">Collections</a></li>
    <li class="credits"><a href="#">Credits</a></li>
  </ul>
 
</nav>
</div>
</td>
</tr>
<tr>
<td>
Table Line
</td>
</tr>
</table>
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<script src="hc-offcanvas-nav.js"></script>
<script>
  jQuery(document).ready(function($) {
    $('#main-nav').hcOffcanvasNav({
      maxWidth: 980,
	  navTitle: 'All pages'
    });
  });
</script>

</body>
</html>

trapFocus ignored & failed removeEventListener by closing with Esc key

Tested on your demo with FF and Chrome - after opening the navbar, items were not trapped.
I remember trap focus was working in the past (I don't remember the version). With the latest 6.0.2 I'm free to jump between elements through the whole page. That should be limited only for the active level.
For now I am using open and open.level events for custom tab-trap.

And also closing the navbar with Esc key causes error in the console
Uncaught TypeError: Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present.

Option to COVER the previous menu?

Is there an option to not show a glimpse of the previous menu behind the active menu group? I want to just have the selected menu cover all the rest - the more deeper you go into the menu - it just gets more crowded. I just want to show one group of menu.

Thanks

Disable swipe gesture when specific elements are being touched

Awesome plugin, it works great.

Currently the menu is always opening and closing when you swipe gesture from the edge of your mobile.
We have a slider element on our page which is full width and whenever we swipe this slider from left to right it causes the menu to open.
How do we prevent the menu from opening when we slide the slider?

open inner menus directly

is it possible to open the directly second or third stack of the menu on a click of a button or link

as in the the below screenshot, is it possible to open Mobile Phones menu directly on a click of a link or button??

image

Hover/focus

Wondering if it would be possible to add ::hover or ::focus classes to the buttons?

levelTitleAsBack is ignored

I suppose the level title should be clickable and contain arrow back instedad of having another item in the navbar called All categories or Back (in default state).

document.addEventListener('DOMContentLoaded', function() {

  var Nav = new hcOffcanvasNav('#main-nav', {
    disableAt: 3000,
    customToggle: '.toggle',
    navTitle: 'All Categories',
    levelTitles: true,
    levelTitleAsBack: true
  });

});

I made a Codepen

How to make it expanded by default ?

I mean, when I open some menu, clicked, page is refreshed, then go back to menu. It opens from scratch, from root.
Exactly I would like to have opened root, opened some level, where the link was clicked, whenever page is refreshed or not.
How ?

Clone entire <li> content into nav menu

Hey, thanks for the great plugin, you have done great job!

I was wondering if the plugin could works with the following structure without trim the '.dont-trim' element:

<nav id="main-nav">
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li class="special-item"><div class="dont-trim"><a href="#">SPECIAL</a></div></li>
  </ul>
</nav>

Now, after plugin initialization .dont-trim element disappears. Is it possible to add some special class like '.special-item' to the <li> element, for example, which tells the plugin to not trim the inner content and keep it in its original structure?

Here is why I need this option. Lets consider that you want to include an entire widget as a menu item. The widget could contains a lot of <div> elements with some CSS classes for styling and <a> tag in the deep. For example:

<div class="special-offer-wrapper">
  <div class="btn-container">
    <a href="some-url">SPECIAL OFFER</a>
  </div>
</div>

This widget could be dynamically loaded, so could be everything, and will be great if is possible to keep its entire original code, as a different special menu item.

Hope this feature could makes the plugin more flexible.

Thanks in advance!
Cheers!

add rtl

please add rtl

just change text nav and icon
image

How can I add custom content?

How can I add custom content?
For example use the slide out for any other content without the menu?

I've just replaced the old mobile menu with hc-offcanvas. However on the other page side we have a content sidebar which until now simply used the old off-canvas menu - but instead of the menu items, we simply displayed other contents.

Keep open on page refresh in a selected item

I wanna ask if its possible keep the menu open when the page refresh or if you select an item.
Maybe there is a way that i can retrieve the selected item and stored on a localstorage variable. there is a way to do that ?
Besides, it is a way that you can disable the offcanvas an used has a side bar ?

Setting maxWidth hide toggle

If maxWidth property was set to 980 (as you provided in your github doc) toggle button hides. Also adding display: block for this toggle is not working because navigation menu is blank after toggle click.

Symbol # in url on submenu click

<a href="#" class="nav-next" aria-label=" Submenu"
After click on a submenu, a symbol # is added to the URL. How to remove it?

Missing opening/closing effect, if size was changed

Hi,
I've just updated from 4.2.5 to 5.0.10, and I found a new issue.
If I open the webpage in a full screen window (above 1024px), then I change its size (below 1024px, so the PC menu is replaced with the mobile menu), and I click to open the mobile menu, there is no effect, and there's no effect when closing either.
If the page was opened below 1024px, then the menu opening/closing working fine.

I hope you understood me, it's quite hard to explain this.
I attached an image (that appears for a second, when I close the menu if the website was first loaded with above 1024px width).
weird

Can the BACK label be able to pull the previous levelTitles?

Instead of always the default BACK regardless of the level depth, I was trying to setup where the BACK button label should pull the previous levelTitle - this make it easier to see how far in and where you are at. Im using the overlap method with no levelSpacing.

Example:

< Training

  • Online
  • Campus

In the above - clicking Training will take you back to the main level/sub level of TRAINING.

Thanks in advance!

How to open nav with screen swipe on mobile devices

Hello somewebmedia , I hope you are doing fine. The navbar would be more robust if we could add a feature to open it on mobile devices through swipe of screen as is available in native apps. I would like to contribute if you wish.

Thank you.

Unable to handle click on sub menu

Hi, I'm not able to handle clicks on items in menu that have a submenu. Is there a way to fix this?

I try to explain better: I have a structure with multiple levels:

zone 1
--->kitchen
------>fridge
--------->food
------>toaster
------>table
--->bath
------>shower
--->bedroom
------>bed
zone2
...
zone 3
.....

I have set a click listener on the <a> tag of the <li> item but everytime I click it opens the sublevel or it closes the menu without trigger the click. How can I fix this? I'm using overlapping levels style for the nav

Plugin does not return plugin object.

Hello

Somehow the plugin is not returning the correct/complete object. See screenshots.
On first screen the object does not contain the close,isOpen,open, etc function .
So, I made a jsfiddle and on that does show the functions..(third screenshot).
If you look at the watch section on 1st and 2nd screen you will see that the return is a regular jQuery object, not the expected plugin object, why?

  • Version: 3.1.2 - Chrome

image

image

image

Keyboard Accessible

Only the back and close is accessible via keyboard - the menu items are not.

Multiple Menus

It would be awesome if multiple menus/navs could be created. Can this be done?

Momentum scrolling

Adding -webkit-overflow-scrolling: touch to .nav-container will result in a wrong clipping and z-index of the overlap menus.

.hc-offcanvas-nav .nav-container {
    position: fixed;
    z-index: 9998;
    top: 0;
    width: 280px;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
    transition: transform .4s ease;
    -webkit-overflow-scrolling: touch;
}

Responsive offcanvas toggler - hide the menu when greater than 576px

I have bind the offcanvas to the the bootstrap hamburger menu. The toggler hamburger menu only shows up when the viewport is below 576px.

Everything works great here when i click the toggler and the menu slides in.

The issue now is that when i resize the browser to greater than 576px - which will hide the hamburger - the offcanvas menu is still visible.

Is there a way to toggle it base on viewport?

I tried using the :

// update the nav DOM - greater than 576px
Nav.close(true);

Active Nav

Is there anyway to show the active nav so if you are in a sub menu page it highlights the page you are on?

Remove code for desktop menu

Hello,
I love your menu and I'm using it for awhile, but I only need it for mobilmenu (below 1024px). I have a different menu for bigger resolutions (PC).
Your menu has the regular version and the mobile version (created from the html template by Javascript).
Could somehow the regular version be erased? It's just hidden (display: none;) for me (that's a lot of html code without use on my website).

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.