Giter Site home page Giter Site logo

slopesweb / responsive-overlay-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marioloncarek/responsive-overlay-menu

0.0 0.0 0.0 343 KB

Framework for making responsive overlay menus

License: MIT License

JavaScript 16.52% CSS 45.25% HTML 38.23%

responsive-overlay-menu's Introduction

responsive-overlay-menu

Framework for making responsive cross-browser overlay menus.

Features

  • works in all browsers
  • works on all device
  • tiny, < 600bytes
  • responsive
  • super fast
  • uses jquery animations
  • framework not a template
  • easy to use
  • free to use and abuse (MIT licence)

Demos

All demos are in examples folder or:

Live Demo

Live demos are avaliable on codepen Responsive overlay menu framework examples

Basic usage

Basic HTML

Put basic HTML somewhere in body section of your web

<div class="menu-btn">
    <a class="btn-open" href="javascript:void(0)"></a>
</div>
<div class="overlay">
</div>

Class menu-btn opens and closes your menu while class overlay is space for your menu (or anything else).

Basic CSS

Styles are stored in style.css. Also this plugin is using ionicons for hamburger menu open and close so please include in <head> (also you will need fonts folder for that) or use other methods for icons (images, any other icon font).

<link rel="stylesheet" href="css/ionicons.min.css">

Styling menu button (hambureger)

.menu-btn {
    position: absolute;
    top: 6px;
    right: 20px;
    z-index: 999;
    display: inline;
    font-size: 32px;
}

.menu-btn a {
    display: inline-block;
    text-decoration: none;
    /* safari hack */
}

.btn-open:after {
    color: #333;
    content: "\f394";
    font-family: "Ionicons";
    -webkit-transition: all .2s linear 0s;
    -moz-transition: all .2s linear 0s;
    -o-transition: all .2s linear 0s;
    transition-property: all .2s linear 0s;
}

.btn-open:hover:after {
    color: #34B484;
}

.btn-close:after {
    color: #fff;
    content: "\f2d7";
    font-family: "Ionicons";
    -webkit-transition: all .2s linear 0s;
    -moz-transition: all .2s linear 0s;
    -o-transition: all .2s linear 0s;
    transition-property: all .2s linear 0s;
}

.btn-close:hover:after {
    color: #34B484;
}

Styling the overlay

.overlay {
    position: fixed;
    top: 0;
    z-index: 99;
    display: none;
    overflow: auto;
    width: 100%;
    height: 100%;
    background: #333;
}

Responsive styles

@media screen and (max-width: 768px) {
    .menu-btn {
        right: 25px;
    }
}

Jquery

Include latest jquery and responsive-overlay-menu.js just before closing </body> tag or in <head>

<script src="js/jquery-1.11.3.min.js"></script>

<script src="js/responsive-overlay-menu.js"></script>

or:

You can also initiate the plugin with <script> </script> tags just before closing </body> tag

$(document).ready(function () {

    $(".menu-btn a").click(function () {
        $(".overlay").fadeToggle(200);
        $(this).toggleClass('btn-open').toggleClass('btn-close');
    });

    $('.overlay').on('click', function () {
        $(".overlay").fadeToggle(200);
        $(".menu-btn a").toggleClass('btn-open').toggleClass('btn-close');
    });

    $('.menu a').on('click', function () {
        $(".overlay").fadeToggle(200);
        $(".menu-btn a").toggleClass('btn-open').toggleClass('btn-close');
    });

});

In both ways jquery must be called on document ready

Advanced Usage and jquery explanation

Usage #1: Basic menu:

$(document).ready(function () {
    $(".menu-btn a").click(function () {
        $(".overlay").fadeToggle(200);
        $(this).toggleClass('btn-open').toggleClass('btn-close');
    });
});

Targets hamburger button and opens overlay class. That means that you can open and close overlay when clicking on hamburer menu. Your menu will work with just that part.

Usage #2: Closing menu when clicking anywhere on overlay

$(document).ready(function () {
    $(".menu-btn a").click(function () {
        $(".overlay").fadeToggle(200);
        $(this).toggleClass('btn-open').toggleClass('btn-close');
    });
    $('.overlay').on('click', function () {
        $(".overlay").fadeToggle(200);
        $(".menu-btn a").toggleClass('btn-open').toggleClass('btn-close');
    });
});

First part is requred code for opening and closing menu, while the second part enables closing the menu when clicking anywhere on your overlay. That means that you dont have to click on close button to close the overlay.

Usage #3: Using menu with anchor links

This will give you possibility to use this menu with one page websites

$(document).ready(function () {
    $(".menu-btn a").click(function () {
        $(".overlay").fadeToggle(200);
        $(this).toggleClass('btn-open').toggleClass('btn-close');
    });
    $('.menu a').on('click', function () {
        $(".overlay").fadeToggle(200);
        $(".menu-btn a").toggleClass('btn-open').toggleClass('btn-close');
    });
});

This will enable closing when clicking on link which points on section on the same page so menu will close it self on click.

Jqury animations

You can use any jquery animation as explained in Jquery api .

Browser compatibility

This plugin is tested with all options and is working on ALL browsers including IE 8+ .

Made with (thanks)

responsive-overlay-menu's People

Contributors

marioloncarek avatar nalipaz 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.