Giter Site home page Giter Site logo

teloe / snazzymenu Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 3.95 MB

Responsive, lightweight, mega menu plugin written in vanilla js and scss

Home Page: https://teloe.me/snazzymenu/

License: MIT License

JavaScript 32.07% HTML 37.24% SCSS 30.69%
javascript js mega-menu menu navigation vanilla-javascript

snazzymenu's Introduction

SnazzyMenu.js

Responsive, lightweight, mega menu

Demo

⚡️ Features

  • Responsive
  • Lightweight (~8kb minified)
  • Fully customizable
  • Sticky menu for both mobile and desktop

🔧 Getting Started

HTML Setup

Include minified CSS and JS from dist/

<link rel="stylesheet" href="path-to-snazzymenu.css">

<script type="text/javascript" src="path-to-snazzymenu.min.js"></script>
<!-- Call snazzyMenu to initialize -->
<script type="text/javascript">
    snazzyMenu.init();
</script>

Define options to override defaults

const options = {
    theme: 'light',
    breakpoint: 1000,
}
snazzyMenu.init(options);

Basic Markup

<div class="snazzymenu">
    <ul class="menu">
        <li class="menu-item-has-children">
            <a href="">Nav Item</a>
            <ul class="sub-menu">
                <li class="menu-item-has-children">
                    <a href="">Column Title</a>
                    <ul class="sub-menu">
                        <li><a href="">Menu Item</a></li>
                        <li><a href="">Menu Item</a></li>
                        <li><a href="">Menu Item</a></li>
                    </ul>
                </li>
                <li><a href="">Column Title</a></li>
                <li><a href="">Column Title</a></li>
                <li><a href="">Column Title</a></li>
            </ul>
        </li>
        <li><a href="">Link to page</a></li>
    </ul>
</div>

🔌 Options

Defaults

const options = {
    theme: 'dark',
    breakpoint: 1024,
    sticky: true,
    toggleBtn: 'caret',
    homeBtn: '<svg fill="currentColor" width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M11.47 3.84a.75.75 0 011.06 0l8.69 8.69a.75.75 0 101.06-1.06l-8.689-8.69a2.25 2.25 0 00-3.182 0l-8.69 8.69a.75.75 0 001.061 1.06l8.69-8.69z"></path><path d="M12 5.432l8.159 8.159c.03.03.06.058.091.086v6.198c0 1.035-.84 1.875-1.875 1.875H15a.75.75 0 01-.75-.75v-4.5a.75.75 0 00-.75-.75h-3a.75.75 0 00-.75.75V21a.75.75 0 01-.75.75H5.625a1.875 1.875 0 01-1.875-1.875v-6.198a2.29 2.29 0 00.091-.086L12 5.43z"></path></svg>',
    phoneBtn: '',
    phoneLabel: 'Call',
    locationBtn: '',
    locationLabel: 'Location',
    setColumnClasses: false,
    setImages: [],
    noControls: false,
}
Property Type Default Description
theme string 'dark' Set theme to .snazzymenu element. 'light' or 'dark'.
breakpoint number 1024 Breakpoint in pixels where menu becomes mobile/desktop friendly.
sticky boolean true Sticky menu on scroll. Set false to disable sticky behavior.
toggleBtn string 'caret' Mobile toggle button icon style. These buttons initiate toggle dropdown for .sub-menu elements. 'caret' or 'plus'.
homeBtn string '' Homepage menu button. Replace default home icon with any custom brand/logo image.
phoneBtn string '' Adds click-to-call phone link. Example: '1-800-555-5555'.
phoneLabel string 'Call' Label for phone button. Replace with any string.
locationBtn string '' Adds location link that opens in new browser tab. Example: 'https://goo.gl/maps/1rnrs4MPkKKSsKPL7'.
locationLabel string 'Location' Label for location button. Replace with any string.
setColumnClasses boolean false Set unique column class names to each li.column-title element in mega menu. This will set class name of li.column-[i] in the order in which they appear.
setImages array [] setColumnClasses must be true. Set the path to images that will show above each li.column-title in the order in which they appear. Example: [ 'path-to-img1.jpg', 'path-to-image2.jpg', etc. ]. This will display images above li.column-1 and li.column-2.
noControls boolean false Removes the top .controls element and shows top-level menu items on desktop viewports only. Set to true will remove hamburger menu, call button, location button, and homepage logo/button.

Adding images to mega menu columns

To show images above each mega menu column, set setColumnClasses to true. This will add unique class names to each li.column-title element inside the mega menu. The markup will look something like this:

<ul class="sub-menu mega-menu">
    <li class="menu-item-has-children has-sub column-title column-1">
        <a href="">Column 1</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
    <li class="menu-item-has-children has-sub column-title column-2">
        <a href="">Column 2</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
    <li class="menu-item-has-children has-sub column-title column-3">
        <a href="">Column 3</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
</ul>

The next step is to add the paths to each image in the setImages array. This will add an image in the order of each li.column-title element. For example:

const options = {
    setColumnClasses: true,
    setImages: [
        'path-to-img1.jpg',
        'path-to-img2.jpg',
        'path-to-img3.jpg',
    ],
};

will output the following markup:

<ul class="sub-menu mega-menu">
    <li class="menu-item-has-children has-sub column-title column-1">
        <img src="path-to-img1.jpg" alt="Navigation image" />
        <a href="">Column 1</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
    <li class="menu-item-has-children has-sub column-title column-2">
        <img src="path-to-img2.jpg" alt="Navigation image" />
        <a href="">Column 2</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
    <li class="menu-item-has-children has-sub column-title column-3">
        <img src="path-to-img3.jpg" alt="Navigation image" />
        <a href="">Column 3</a>
        <ul class="sub-menu">
            <!-- sub-menu items -->
        </ul>
    </li>
</ul>

Note: images are only visible on desktop viewports.

snazzymenu's People

Contributors

teloe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

andre-vincent

snazzymenu's Issues

Move single sub menu beneath column title

I have this menu

menu1 (single sub menu) menu2 (single sub menu) menu 3 (megamenu) menu 4 (megamenu)

My four sub items under menu1 and menu2 is placed all to the left of the screen. Can't it be placed right under the column title?

image

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.