Giter Club home page Giter Club logo

kin-menu's Introduction

Kin Menu

Create a menu for small screen devices using elements within the page. Example, from your website's main navigation.

Contents

Usage

Add the JS file

<script defer src="https://cdn.jsdelivr.net/gh/madebygrant/[email protected]/dist/js/kin-menu.min.js">

Add the CSS stylesheet

The CSS is optional but ideally at least include the base css file to build off from.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/madebygrant/[email protected]/dist/css/kin-menu.all.css">

If you want just want to use the base css stylesheet without the included styles:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/madebygrant/[email protected]/dist/css/kin-menu.base.css">

Initialise Kin Menu

const kinOptions = {
	// Your options go here.   
}
const kin = new KinMenu(kinOptions);
kin.init();

Hide items when the menu is active

Within your website's CSS stylesheet, include a rule similar to the example below, for when the kin-is--loaded class has been added to the <body> tag.

body.kin-is--loaded { 
    .top-menu{
        display: none;
    }
}

Options

Option Type Description Defaults
windowWidth integer The maximum width of the window size to activate the plugin 960
pageContent string, node The element where the main content of the website is located within. First <main> tag in the page.
toggleButton object Where you can modify the toggle button { spans: 3, text: '', hasWrapper: false, wrapperContent: false }
groups array The items you want to add into the Kin Menu

Adding items to the Kin Menu

  • groups: Set groups for your cloned elements to be added within Kin Menu.
    • element: Determine which element type to wrap the clones in.
    • class: Apply class to your group wrap element. For multiple classes, do so with an array.
    • clones: Select the items within the page to be added into the group.

The example below, it adds the <li> items from a <nav> (nav.top-menu) in the page into a group (ul.side-menu) in the Kin Menu.

const kinOptions = {
    groups: [
        {
            element: 'ul',
            class: 'side-menu',
            clones: [
                'nav.top-menu > ul > li'
            ]
        },
    ]
};

const kin = new KinMenu(kinOptions);
kin.init();

The example below, shows how to add multiple groups and items into the Kin Menu.

const kinOptions = {
    windowWidth: 1024,
    groups: [
        {
            element: 'header',
            class: 'side-header',
            clones: [
                'figure.site-logo',
                'h1.site-heading'
            ]
        },
        {
            element: 'ul',
            class: 'side-menu',
            clones: [
                'nav.top-menu > ul > li'
            ]
        },
        {
            element: 'div',
            class: 'side-social-media',
            clones: [
                'div.social-media a'
            ]
        },
    ]
};

const kin = new KinMenu(kinOptions);
kin.init();

Toggle Button Options

Option Type Description Defaults
spans integer Number of <span> elements to generate in the button for styling purposes 3
text string Text to include inside of the button ''
hasWrapper boolean Create a <div> wrapper around the button. false
wrapperContent array Select items within the page to be added into in the wrapper

The example below, adds a <figure> (figure.site-logo) element from the page into the toggle button's wrapper, next to the button.

const kinOptions = {
    groups: [
        {
            element: 'ul',
            class: 'side-menu',
            clones: [
                'nav.top-menu > ul > li'
            ],
        },
    ],
    toggleButton: {
        hasWrapper: true,
        wrapperContent: [
            'figure.site-logo'
        ]
    }
};

const kin = new KinMenu(kinOptions);
kin.init();

Styles

Currently has four loosely styled styles but totally optional. It requires the kin-menu.all.css stylesheet to be loaded.

To apply a style, either:

  • Add a data-kin attribute to the <body> tag with the corresponding option value.
  • Apply the setStyle() method to the initialised Kin Menu object and give it the corresponding option value.
    Example: kin.setStyle('side-angled);
Style Option Value Description
Side side A basic side menu that slides in from the left.
Angled Side side-angled A angled side menu that slides in from the left
Circle Expand circle-expand The toggle button's background expands to full screen and the menu appears afterwards.
Transition transition An animated, full width that menu slides down from the top.

Note: The .scss files are located in the 'src' directory in the repository

Methods

init

Initialise the menu

kin.init();

create

Create and render the menu

kin.create();

destroy

Destroy the menu

kin.destroy();

setStyle

Apply a style to the menu

kin.setStyle();

License

This project is available under the MIT license.

kin-menu's People

Contributors

madebygrant avatar

Stargazers

 avatar  avatar

Watchers

 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.