All Projects â†’ grubersjoe â†’ Slide Menu

grubersjoe / Slide Menu

Licence: mit
A multilevel page menu with a smooth slide effect

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Slide Menu

Hamburger React
Animated hamburger menu icons for React (1.5 KB) 🍔
Stars: ✭ 391 (+272.38%)
Mutual labels:  transitions, menu
Quickmenu
The new era of mobile navigation for the web, we're out of hamburgers.
Stars: ✭ 119 (+13.33%)
Mutual labels:  menu, scss
Sunset.css
This library offers a collection of different CSS-powered transitions.
Stars: ✭ 99 (-5.71%)
Mutual labels:  transitions
Zenburn
SublimeText, iterm, xcode, css, and textmate themes modeled after the vim zenburn theme.
Stars: ✭ 103 (-1.9%)
Mutual labels:  scss
Wordless
All the power of Pug, Sass, Coffeescript and WebPack in your WordPress theme. Stop writing themes like it's 1998.
Stars: ✭ 1,374 (+1208.57%)
Mutual labels:  scss
Redux Time
∞ High-performance declarative JS animation library for building games, data-viz experiences, and more w/ React, ThreeJS, Inferno, SnabbDOM and others...
Stars: ✭ 99 (-5.71%)
Mutual labels:  transitions
Design System
Design system for new Proton project
Stars: ✭ 101 (-3.81%)
Mutual labels:  scss
Sassdoc
Release the docs!
Stars: ✭ 1,353 (+1188.57%)
Mutual labels:  scss
Cascade
Nested popup menus with smooth height animations
Stars: ✭ 1,493 (+1321.9%)
Mutual labels:  menu
Sassline
Set text on the web to a baseline grid with Sass & rems using a responsive modular-scale.
Stars: ✭ 1,374 (+1208.57%)
Mutual labels:  scss
Webpack4.x
webpack4.xèŻŠç»†é…çœźæ­„éȘ€
Stars: ✭ 103 (-1.9%)
Mutual labels:  scss
Opentracing.io
OpenTracing website
Stars: ✭ 100 (-4.76%)
Mutual labels:  scss
Engineering Blog
📝 We write about our technologies and the problems we handle at scale.
Stars: ✭ 99 (-5.71%)
Mutual labels:  scss
Sass Brunch
Adds Sass / Scss support to brunch
Stars: ✭ 102 (-2.86%)
Mutual labels:  scss
Awescnb
🎹 ćż«é€Ÿæž„ć»șă€ćź‰èŁ…ă€ćˆ‡æąćšćźąć›­çšźè‚€
Stars: ✭ 99 (-5.71%)
Mutual labels:  scss
Bitters
Bitters is maintained by the thoughtbot design team. It is funded by thoughtbot, inc. and the names and logos for thoughtbot are trademarks of thoughtbot, inc.
Stars: ✭ 1,398 (+1231.43%)
Mutual labels:  scss
Hugo Theme Even
🚀 A super concise theme for Hugo https://hugo-theme-even.netlify.app
Stars: ✭ 1,351 (+1186.67%)
Mutual labels:  scss
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (-4.76%)
Mutual labels:  menu
Coreui Angularjs
CoreUI AngularJS is free AngularJS admin template based on Bootstrap 4
Stars: ✭ 101 (-3.81%)
Mutual labels:  scss
Bootstrap 4 Utilities
Bootstrap 4 utility classes in LESS CSS for Bootstrap 3 or any other projects.
Stars: ✭ 105 (+0%)
Mutual labels:  scss

Slide Menu

A library agnostic multilevel page menu with a smooth slide effect based on CSS transitions and various options.

Support: All current browsers and IE11+ (if using dist/slide-menu.ie.js).

Demo

Breaking changes

Version 1.0 has been released and includes breaking changes: SlideMenu no longer depends on jQuery and the library has been rewritten in TypeScript. See below instructions how to use the current version.

Install

npm install @grubersjoe/slide-menu

Now import dist/slide-menu.js and dist/slide-menu.css in your bundler or build system of choice or use a 1998 <script> and <link> tag. Afterwards SlideMenu will be available in the global namespace (window.SlideMenu).

To keep the bundle size small (17 kB vs. 22 kB) Internet Explorer 11 is not supported out of the box. If you need to support Internet Explorer 11 use dist/slide-menu.ie.js instead.

Usage

All you need is the traditional CSS menu HTML markup and a wrapper with the class slide-menu. Menus can be nested endlessly to create the desired hierarchy. If you wish to programmatically control the menu, you should also set an ID to be able to use the API (see below).

Example

<nav class="slide-menu" id="example-menu">
  <ul>
    <li>
      <a href="#">Home</a>
      <ul>
        <li><a href="#">Submenu entry 1</a></li>
        <li><a href="#">Submenu entry 2</a></li>
        <li><a href="#">Submenu entry 3</a></li>
      </ul>
    </li>
    <li>
      <a href="/blog">Blog</a>
    </li>
    <li>
      <a href="/about">About</a>
    </li>
  </ul>
</nav>

Create the menu then like this:

document.addEventListener("DOMContentLoaded", function () {
  const menuElement = document.getElementById('example-menu');
  const menu = new SlideMenu(menuElement);
});

Options

The SlideMenu() constructor takes an optional second parameter to pass in various options:

Option Description Valid values Default
backLinkAfter HTML to append to back link in submenus HTML code ''
backLinkBefore HTML to prepend to back link in submenus HTML code ''
keycodeClose Key used to close the menu Any valid KeyboardEvent key undefined
keycodeOpen Key used to open the menu Any valid KeyboardEvent key undefined
position Position of the menu 'left' or 'right' 'right'
showBackLink Add a link to navigate back in submenus (first entry) boolean true
submenuLinkBefore HTML to prepend to links with a submenu HTML code ''
submenuLinkAfter HTML to append to links with a submenu HTML code ''

Example:

document.addEventListener("DOMContentLoaded", function () {
 const menu = new SlideMenu(document.getElementById('example-menu'),{
     showBackLink: false,
     submenuLinkAfter: ' <strong>⇒</strong>'
 });
});

API

You can call the API in two different ways:

  • Reuse the reference to the SlideMenu instance:

    const menu = new SlideMenu(document.getElementById('example-menu'));
    
    // ... later
    menu.close();
    
  • The SlideMenu instance is also added as property of the menu DOM element (I'm still not sure if this might be a really bad idea). So if you need to control an existing menu without a reference to it, you can fetch it any time this way:

    const menu = document.getElementById('example-menu')._slideMenu;
    menu.open();
    

Methods

  • close(animate = true) - Close the menu
  • back() - Navigate on level back if possible
  • destroy() - revert all DOM changes made by SlideMenu. This includes inline styles, but not the slide-menu class name for the container element.
  • navigateTo(target) Open the menu level which contains specified menu element. target can either be a document.querySelector compatible string selector or the the DOM element (inside the menu). The first found element (if any) will be used.
  • open(animate = true) - Open the menu
  • toggle(animate = true) - Toggle the menu

Events

SlideMenu emits events for all kind of actions, which trigger as soon as the action is method is called. Plus, all events have also an <event>-after equivalent, which is fired after the step is complete (completely animated).

  • sm.back[-after] fires immediately when navigating backwards in the menu hierarchy or after the animation is complete respectively.
  • sm.close[-after] fires immediately when the close() method is called or after the animation is complete respectively.
  • sm.forward[-after]fires immediately when navigating forward in the menu hierarchy or after the animation is complete respectively.
  • sm.navigate[-after]fires immediately when calling the navigateTo() method or after the animation is complete respectively.
  • sm.open[-after] fires immediately when the open() method is called or after the animation is complete respectively.

Make sure to add the event listener to the HTML element, which contains the menu, since the events for this specific menu are dispatched there:

document.addEventListener("DOMContentLoaded", function () {
  const menuElement = document.getElementById('example-menu');
  const menu = new SlideMenu(menuElement);

  // Attach the event listener to the *DOM element*, not the SlideMenu instance
  menuElement.addEventListener('sm.open', function () {
    console.log('The menu opens');
  });

  menuElement.addEventListener('sm.open-after', function () {
    console.log('The menu has opened');
  });
});

Control buttons

Buttons to control the menu can be created easily. Add the class slide-menu__control to anchors or buttons and set the data attributes target to the ID of the desired menu and action to the API method:

<button type="button" class="slide-menu__control" data-action="open">Open</button>
<button type="button" class="slide-menu__control" data-action="back">Back</button>

Inside the menu container the attribute data-target can be omitted or set to to the string this to control this menu.

<a class="slide-menu-control" data-action="close">Close this menu</a>
<a class="slide-menu-control" data-target="this" data-action="close">Close this menu</a>

Development

yarn install
yarn start:dev

Open http://localhost:9000/.

To create a production build:

yarn build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].