Giter Club home page Giter Club logo

hamburgers's Introduction

Hamburgers

Hamburgers is a collection of tasty CSS-animated hamburger icons. Also included is the source as a Sass library. It’s modular and customizable, so cook up your own hamburger.

Table of Contents

Usage

  1. Download and include the CSS in the <head> of your site:
<link href="dist/hamburgers.css" rel="stylesheet">
  1. Add the base hamburger markup:
<button class="hamburger" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>  

You can use <div>s if you insist, but they’re not accessible as a menu button.

<div class="hamburger">
  <div class="hamburger-box">
    <div class="hamburger-inner"></div>
  </div>
</div>
  1. Append the class name of the type of hamburger you’re craving:
<button class="hamburger hamburger--collapse" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

Here’s the list of hamburger-type classes you can choose from:

hamburger--3dx
hamburger--3dx-r
hamburger--3dy
hamburger--3dy-r
hamburger--3dxy
hamburger--3dxy-r
hamburger--arrow
hamburger--arrow-r
hamburger--arrowalt
hamburger--arrowalt-r
hamburger--arrowturn
hamburger--arrowturn-r
hamburger--boring
hamburger--collapse
hamburger--collapse-r
hamburger--elastic
hamburger--elastic-r
hamburger--emphatic
hamburger--emphatic-r
hamburger--minus
hamburger--slider
hamburger--slider-r
hamburger--spin
hamburger--spin-r
hamburger--spring
hamburger--spring-r
hamburger--stand
hamburger--stand-r
hamburger--squeeze
hamburger--vortex
hamburger--vortex-r

Note: -r classes are reverse variants (e.g. hamburger--spin spins clockwise whereas hamburger--spin-r spins counterclockwise.

  1. Trigger the active state by appending class name is-active:
<button class="hamburger hamburger--collapse is-active" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

Since the class name would have to be toggled via JavaScript and implementation would differ based on the context of how you plan on using the hamburger, I’m going to leave the rest up to you.

Sass

.scss source files are available if you use Sass as your CSS precompiler. It’s customizable and modular.

  1. Hamburgers is available on npm, yarn and Bower.
npm install hamburgers

yarn add hamburgers

bower install css-hamburgers

Also available as a Ruby gem to use within your Rails application—see below for more information.

Or to manually install it, download and unzip the source files, then copy the files from the _sass/hamburgers directory into your project.

  1. Import the hamburgers.scss file in your Sass manifest file:
@import "path/to/hamburgers";
  1. Customize your hamburger and/or remove any types you don’t want in hamburgers.scss.
  2. Compile your Sass*, and voila!

* Be sure to run the CSS through Autoprefixer since the Sass doesn’t account for vendor prefixes.

Install for Ruby on Rails

  1. Add Hamburgers to your Gemfile.
gem 'hamburgers'
  1. Run bundle install.
  2. Include Hamburgers by using Sass’s native @import**:
// application.scss
@import "hamburgers";

** More information on why Sass’s native @import + why you should ditch Sprockets directives altogether.

Customization

To override default settings, declare them before importing Hamburgers:

$hamburger-padding-x: 20px;
$hamburger-padding-y: 15px;
$hamburger-types     : (collapse);

@import "hamburgers";

You can also create a separate file (e.g. hamburgers-settings.scss) with those declarations, then import it before Hamburgers:

@import "hamburgers-settings"
@import "hamburgers";

Here is the full list of default settings (found in _sass/hamburgers/hamburgers.scss);

$hamburger-padding-x           : 15px;
$hamburger-padding-y           : 15px;
$hamburger-layer-width         : 40px;
$hamburger-layer-height        : 4px;
$hamburger-layer-spacing       : 6px;
$hamburger-layer-color         : #000;
$hamburger-layer-border-radius : 4px;
$hamburger-hover-opacity       : 0.7;
$hamburger-active-layer-color  : $hamburger-layer-color;
$hamburger-active-hover-opacity: $hamburger-hover-opacity;

// To use CSS filters as the hover effect instead of opacity,
// set $hamburger-hover-use-filter as true and
// change the value of $hamburger-hover-filter accordingly.
$hamburger-hover-use-filter   : false;
$hamburger-hover-filter       : opacity(50%);
$hamburger-active-hover-filter: $hamburger-hover-filter;

// Remove or comment out the hamburger types you don’t want
// or need, so they get excluded from the compiled CSS.
$hamburger-types: (
  3dx,
  3dx-r,
  3dy,
  3dy-r,
  3dxy,
  3dxy-r,
  arrow,
  arrow-r,
  arrowalt,
  arrowalt-r,
  arrowturn,
  arrowturn-r,
  boring,
  collapse,
  collapse-r,
  elastic,
  elastic-r,
  emphatic,
  emphatic-r,
  minus,
  slider,
  slider-r,
  spring,
  spring-r,
  stand,
  stand-r,
  spin,
  spin-r,
  squeeze,
  vortex,
  vortex-r
);

ems or rems

Wanna work with ems or rems instead of px? Just change all the px values to the unit of your choice. Note: Be consistent (all px or all ems), otherwise it may break—the math behind the customization will fail if it attempts to perform operations with values of different units.

Not satisfied?

Dig into _base.scss or types/ and customize to your heart’s content. Fair warning: It‘s pretty delicate and may break, especially if you tweak the animations themselves.

Accessibility

Hamburger menu icons can be useful in the right context, but they’re not the most accessible.

ARIA will help make it accessible to people with disabilities.

<nav>
  <button class="hamburger hamburger--elastic" type="button"
          aria-label="Menu" aria-controls="navigation" aria-expanded="true/false">
    <span class="hamburger-box">
      <span class="hamburger-inner"></span>
    </span>
  </button>

  <div id="navigation">
    <!--navigation goes here-->
  </div>
</nav>

You will need JavaScript to toggle between aria-expanded attribute being set to true and false, as this will indicate to visually impaired users whether the menu is opened or closed.

The hamburger button belongs inside the <nav> so that assistive technologies will be able to locate the navigation, and to allow these users to easily locatate the hamburger button, without having to search up and down the DOM, once they realize they've found themselves in an empty navigation.

If you insist on using <div>s, by default they’re not focusable (i.e. via keyboard or assistive technology). Add the tabindex attribute alongside ARIA. You will also need to recreate expected keyboard functionality for these <div>s. Using JavaScript, you will need to make sure that both Space and Enter will toggle the hamburger states.

<nav id="navigation">

  <div class="hamburger hamburger--elastic" tabindex="0"
       aria-label="Menu" role="button" aria-controls="navigation" aria-expanded="true/false">
    <div class="hamburger-box">
      <div class="hamburger-inner"></div>
    </div>
  </div>

  <div id="navigation">
    <!--navigation goes here-->
  </div>
</nav>

A label will help make it more obvious that it toggles a menu.

<button class="hamburger hamburger--collapse" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
  <span class="hamburger-label">Menu</span>
</button>

Here are some resources on web accessibility and ARIA.

Browser Support

Animations use CSS3 3D transforms (translate3d whenever possible for GPU acceleration), which is supported by most browsers (not supported by IE9 and older and Opera Mini). For detailed browser support, check caniuse.com.

hamburgers's People

Contributors

alanhogan avatar andreamaiolo avatar curvesfr avatar dependabot[bot] avatar ecastillo avatar giordanovi avatar helloilya avatar jonsuh avatar lewebsimple avatar osule avatar s-vlad avatar scottaohara 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  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

hamburgers's Issues

Package deprecated on npm

Was this a mistake? Message says @v1.0.0 (which has been removed) but it seems like the whole package is deprecated.

screen capture on 2018-10-05 at 11-32-46 1

Docs typo

yarn get hamburgers is not a valid yarn command. yarn add hamburgers is what you want I think.

Receiving support?

Hi there! This isn't a issue but I didn't know where to ask!
Are you accepting donations or supports? Because may you get some extra support for hamburgers, but there is no donate button o something like that.
I don't trying to spam you, but I want to invite you to beerpay.io, a simple platform to monetize open source projects, like hamburgers.
I know that the open source is free, but it's okay if someone want to contribute in other way.

Thanks for this work man!

Compatibility with Bootstrap 4 issue

I am trying to use your hamburgers instead of Bootstrap's default one. I changed this part o fthe code

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

to be

<button class="hamburger hamburger--slider" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="hamburger-box">
        <span class="hamburger-inner"></span>
    </span>
</button>

The hamburger icon is present, however, the animation is not working for some reason that I don't understand. Do you have any idea why isn't it working?

How to override default settings when using "Hamburgers" in multiple place?

Assume i'm using "Harmurgers" for mobile menu icon, and for another case as a closing X icon for a popup box.

As mentioned in the customization section of "Hamburgers" here, i can make overriding default settings such as setting the following sass variables:

$hamburger-layer-width                     : 20px;
$hamburger-layer-height                    : 1px;
$hamburger-layer-color                     : #ccc;

But in case i use Hamburgers in 2 different places as i mentioned, these sass variables will override settings in all places!

So how to deal with that?

Adding classes to provide different sizes

Hi there,

I like how this stuff made hamburger icons easy to handle! Thank you for your effort.

It would be great if there are classes to be used to control size, for example like adding class large, medium or small to give different sizes look. Or some another method to control hamburger icons size.

Recommendation: Relative units

Instead of using fixed pixel units, it would add a lot more flexibility using em.
I already did it on a project and could create a PR.

Controlling color without SCSS

Trying to see what is the easiest, most future-compatible way to control colors in a non-SCSS setup.

Is this the way to go?

.hamburger .hamburger-inner, .hamburger .hamburger-inner:after, .hamburger .hamburger-inner:before {
  background-color: #666;
}

If so, can I suggest maybe adding another class to these elements that will allow something like:

.hamburger-icon { background-color: #666; }

Close on click

How to close hamburger on click?

In my case is needed because it is used in one page site.

js needed

Hi, I think you should mention on your documentation that one should add the hamburgers.js file or add a click mouse event that toggles an is-active class on the button?

Add setting for active state

It would be great to add a setting to control the active state of the icon. So we can change the colour of the cross etc.
Lovely work though. Thanks.

Annoying blue - selection lines

Hey there,

I'm struggling to remove the annoying line next to the hamburger button.. It shows in Chrome and Safari as well and I have no idea why.

Here is what I'm talking about:

screen shot 2017-07-22 at 09 50 35
screen shot 2017-07-22 at 09 50 46

Also, when I'm resizing the layers and the spacing for example. They get messed up, the spacing between them is going to be different and the height of (usually just the top) the layer gets smaller than the others.

Any idea on how, to remove them?

Color change on hover

I'm trying to make the hamburger change color on hover, but it's obviously coming into conflict with some CSS, and as a result the patty and buns are changing color at a different rate. Is there any good workaround to this?

Make hamburger stationary when toggled

Hi.

I love this plugin but I'm trying to edit the css such that when the hamburger is clicked, the positioning doesn't change such that the X is underneath the toggled menubar. Is this possible? If so, what do I need to change in the css? I'm using 3DX transition. Any help is appreciated.

Also, there is an outline on the hamburger after I click it. Is there any way to remove that outline?

Accessibility Recommendation

Hello :) Good work here!

I'd love for you to consider users that may be using a keyboard or assistive technology. They can't send focus to the burger because <divs> are not focusable. This is because a <div> is used where perhaps <a> or <button> could be used. Doing this along with visually hiding some text content inside the anchor provides assistive technology something to work with.

You can test this by trying to access your burger by unplugging your mouse and try to tab to it. Here's a code snippet that could be considered:

<a class="hamburger" href="#some-navigation">
  <span class="visually-hidden">Main Navigation</span>
  <div class="hamburger-box">
    <div class="hamburger-inner"></div>
  </div>
</a>

href points to ID placed on element it controls. The author then could add aria to further enhance the accessibility. e.g. aria-controls aria-expanded etc.

If you MUST use a <div> adding tabindex="0" would make them focusable but is not ideal. Also role="button" should be added as well. :(

[Feature Request] Make it react components?

Hello, first of all, thank you for this wonderful library.
As app grows, its easier to make hamburgers a react component.
Something like this

<Hamburger
  active={this.state.active}
  type="slider"
  onClick={() => this.setState({ active: !this.state.active })}
/>

And add react-emotion support, there won't be any css conflict and additional sass logic.
Thank you.

_sass files could all be in extendable placeholders.

For the sass structure, do you think it might be helpful to rewrite the library using placeholders instead of classes? Ex:

%hamburger-slider-r {
  .hamburger-inner { }
}

That could help in a situation where somebody is getting the whole package but only want to use one of the transitions, and don't want to inflate the code with the ones they don't use.

hamburgers.sass cannot be imported(SCSS)

The hamburgers.sass cannot be imported in my company's project because of the hamburger.sass path has been assigned to the SASS_PATH environment variable, and somehow this environment variable is not being included when the asset compile. I end up pushing the hamburgers.sass's path to the asset_paths array in my project's config file. As in the Rails gem guide, I suggest to put it under one of the directories, app/assets, lib/assets or vendor/assets. http://guides.rubyonrails.org/asset_pipeline.html#adding-assets-to-your-gems

More types

On demo we see just two types of "hamburguers", arrow and cross...
So, we can add more? Ideas?

change active class to 'active'

Hi! It would be great if you changed the active class to 'active' instead of is-active, since the dashed version can sometimes lead to some problems.

I know we can just mod the scss files, yes, no prob, but then updates would be broken (and again, yes, it would be simple to fix it up as well, but it would be simpler to keep things simple :)).

Thanks for your great code, Regards

Size of icon

Hello there!
How can I adequately change the size of icon?

Currently the hamburger menu will not animate when clicked

Not sure why it is behaving that way

No code changed in the sass files and this is what i have on my page

<button class="hamburger hamburger--emphatic" type="button">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
  <br />
  <span class="hamburger-label">Menu</span>
</button>

Convert to mixin

Hey,

This is not an issue, more a recommendation or a note :)

I've turned your sass code into a single mixin, which is easy to include and customize:

@mixin burger($options: ()) {

  // Default settings
  // To customize just pass in the arguments in a map
  // Example:
  // @include burger((padding: 30px))
  $config: map-merge((
    padding: 15px,
    width: 40px,
    height: 4px,
    spacing: 6px,
    color: black,
    border-radius: 4px,
    hover-opacity: 0.7,
    background-color: black,
    hover-transition-duration: 0.15s,
    hover-transition-timing-function:  linear,
  ), $options);

  // Get the map properties and asign them to variables for improved readabilty
  $padding: map-get($config, padding);
  $width: map-get($config, width);
  $height: map-get($config, height);
  $spacing: map-get($config, spacing);
  $color: map-get($config, color);
  $border-radius: map-get($config, border-radius);
  $hover-opacity: map-get($config, hover-opacity);
  $background-color: map-get($config, background-color);
  $hover-transition-duration: map-get($config, hover-transition-duration);
  $hover-transition-timing-function: map-get($config, hover-transition-timing-function);

  // Styles
  // --------------------------------------------------------------------------

  padding: $padding;
  background-color: $background-color;

  &:hover {
    opacity: $hover-opacity;
  }

  .hamburger__container {
    width: $width;
    height: $height * 3 + $spacing * 2;
  }

  .hamburger__inner {
    transition: opacity $hover-transition-duration $hover-transition-timing-function;
    margin-top: $height/ -2;
    &,
    &::before,
    &::after {
      width: $width;
      height: $height;
      background-color: $background-color;
      border-radius: $border-radius;
    }

    &::before {
      top: ($spacing + $height) * -1;
    }

    &::after {
      bottom: ($spacing + $height) * -1;
    }
  }

}

.hamburger {
  display: inline-block;
  cursor: pointer;
}

// Undo button styles
button.hamburger {
  appearance: none;
  background-color: transparent;
  border: 0;
  margin: 0;
  overflow: visible;
}

.hamburger__container {
  display: inline-block;
  position: relative;
}

.hamburger__inner {
  display: block;
  top: 50%;

  &,
  &::before,
  &::after {
    position: absolute;
    transition-property: transform;
    transition-duration: 0.15s;
    transition-timing-function: ease;
  }

  &::before,
  &::after {
    content: '';
    display: block;
  }
}

This way you include the burger like this:

.my-class {
  @include burger(( height: 30px ));
}

Multiple animations then could be included with an if/else block.

Hamburgers are not vertically aligned to center of button

My hamburger settings:

$hamburger-padding-x: 3px;
$hamburger-padding-y: 0;
$hamburger-layer-width: 24px;
$hamburger-layer-height: 2px;
$hamburger-layer-spacing: 5px;

With Normalize.css, a style with

font-family: sans-serif;
font-size: 100%;
line-height: 1.15;
margin: 0;

will be applied to the <button> element causing the button to have a height of 24px whereas my hamburger will only have 16px height with the settings above.

screen shot 2018-10-04 at 10 51 41 am

As per the screenshot, you can see the hamburger does not align with the button's height vertically.

First thing I tried

Adding vertical-align: middle to .hamburger-box.

screen shot 2018-10-04 at 11 03 35 am

But it still doesn't seem vertically centered.

Second (which hopefully is a better solution for hamburgers)

Giving .hamburger a width and height property, and position centering .hamburger-box in relative to .hamburger as such.

.hamburger {
   width: 32px; // can be overwritten by button css
   height: 32px; // can be overwritten by button css
   position: relative;
}

.hamburger-box {
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
}

Giving us this.

screen shot 2018-10-04 at 11 06 28 am

I can create a PR for this if you'd like @jonsuh

Cheers

Pure CSS support

It could be good if pure css support is available.
When using purecss you do this:
Html:
checkbox
label
CSS:

input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked + label {
 //alternate css rules for label (the same as .is_active)
}

PureCSS is a common practice in well developed websites.

bower

...It would be lovely have this available via bower :)

Swap @if burguers statement into a @mixins

Hello, nice burgers 👍 🍔 !

Usually each project has just one burguer.
And of course we can go into the files and comment the @import, but this means touching files in node_modules ( that problably will rely on a problem if we try a package version update ) 😢 .

Wouldn't be a better approach just have @mixins for each burguer ( and have them listed in the DOC) so i can @include just the one that i want ?

Keeping your files clean 😃.

Firefox issue

Hi,
I've spotted an issue while using this library with Firefox. Once the transition is complete, the icon (after some milliseconds) lose its thickness. Am I the only one that is experiencing this problem?

"Spin Reverse" wrong calculation

.hamburger--spin-r.is-active .hamburger-inner::after for "spin reverse" needs to be rotated 90deg instead of -90deg like the normal spin (line 36 in spin-r.scss)

ASCII Encoding Error

There is an error when importing hamburger.scss into Sass projects.

There error line begins with:

Error: Invalid US-ASCII character \"\xE2\"

See PR #17. Thanks.

Control speed of transition

I don't seem to find a way of controling the time the transition takes to complete/ the speed of the burger.
Is this really missing?

Bower support

@jonsuh: It would be awesome if Hamburgers supported installation via Bower. If you're open to that idea, I can send a pull request your direction with the necessary updates.

Issue animating the burger menu

I am animating a burger menu changing the margin and width of two divs, and in the meantime, a burger icon it is animated switching the class is-active.

The result, as you can see, is a jumpy effect in the content of the burger menu (green area):
http://www.codeply.com/go/7xjGnw5yEc

Executing the burger button: you can see that, for some miliseconds, the green area dissapears.
Executing the toggle button: you can see that there are no jumps.

I only reproduce it in Google Chrome.

What is it happening? How can I fix this strange behaviour?

Double click on Ipad

Hi it's very useful on desktop. However i have a little issue. When i'm using a script on an ipad. I have to double click on the icon to see result. Regards

Doesn't work! :(

So I have the css and it linked in I have put the code in the and absolutely nothing happens? I click and get nothing.
screen shot 2018-04-18 at 15 03 21

Uncss friendly version?

With the following classes ignored:

'.is-active','*.is-active', '.hamburger--collapse','.hamburger-*', '.hamburger-inner', '.hamburger', '.hamburger-box',
        '.hamburger--collapse-r.is-active', '.hamburger--collapse.is-active', '.hamburger--collapse-r',
        '.hamburger--collapse.is-active', '.hamburger-inner::before', '.hamburger-inner::after',

and the following markup:

<button class="hamburger hamburger--collapse" type="button" aria-label="Menu" aria-controls="navigation">
  <span class="hamburger-box">
    <span class="hamburger-inner"></span>
  </span>
</button>

I'm unable to get any hamburger on my mobile display and even on the desktop I'm not able to retain the animations...

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.