Top Related Projects
jQuery contextMenu plugin & polyfill
:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
Quick Overview
Hamburgers is a collection of CSS-animated hamburger icons for use in web projects. It provides a variety of customizable hamburger menu animations, allowing developers to easily implement interactive menu toggles without writing complex CSS animations from scratch.
Pros
- Easy to implement with minimal CSS and JavaScript
- Highly customizable with SASS variables
- Lightweight and performant animations
- Wide variety of animation styles to choose from
Cons
- Requires SASS compilation for full customization
- Limited to hamburger menu animations only
- May require additional JavaScript for full menu functionality
- Some animations might be too elaborate for certain design aesthetics
Code Examples
Basic usage with default settings:
<button class="hamburger hamburger--spin" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
Customizing colors using SASS variables:
$hamburger-color: #ff0000;
$hamburger-hover-opacity: 0.8;
@import "hamburgers/hamburgers";
Triggering the animation with JavaScript:
const hamburger = document.querySelector('.hamburger');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('is-active');
});
Getting Started
-
Install Hamburgers via npm:
npm install hamburgers
-
Import the SCSS file in your project:
@import "~hamburgers/_sass/hamburgers/hamburgers";
-
Add the HTML for the hamburger icon:
<button class="hamburger hamburger--squeeze" type="button"> <span class="hamburger-box"> <span class="hamburger-inner"></span> </span> </button>
-
Initialize the animation with JavaScript:
document.querySelector('.hamburger').addEventListener('click', function() { this.classList.toggle('is-active'); });
Competitor Comparisons
jQuery contextMenu plugin & polyfill
Pros of jQuery-contextMenu
- Provides a full-featured context menu solution, including submenus and various item types
- Offers extensive customization options for menu appearance and behavior
- Includes built-in keyboard navigation support
Cons of jQuery-contextMenu
- Requires jQuery as a dependency, which may increase overall project size
- More complex setup and configuration compared to simpler menu solutions
- May have a steeper learning curve for developers new to context menus
Code Comparison
jQuery-contextMenu:
$.contextMenu({
selector: '.context-menu-one',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: function($element, key, item){ return 'context-menu-icon context-menu-icon-quit'; }}
}
});
Hamburgers:
@import "hamburgers";
.hamburger {
@include hamburger();
}
Note: The code comparison is not directly equivalent as the projects serve different purposes. jQuery-contextMenu is for creating context menus, while Hamburgers is for creating animated hamburger icons.
:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
Pros of react-burger-menu
- Specifically designed for React applications
- Offers multiple pre-built menu styles and animations
- Includes built-in accessibility features
Cons of react-burger-menu
- Limited to React projects, not suitable for vanilla JavaScript or other frameworks
- May require additional configuration for complex customizations
- Larger bundle size due to React dependency
Code Comparison
react-burger-menu:
import { slide as Menu } from 'react-burger-menu'
<Menu>
<a id="home" className="menu-item" href="/">Home</a>
<a id="about" className="menu-item" href="/about">About</a>
<a id="contact" className="menu-item" href="/contact">Contact</a>
</Menu>
hamburgers:
<button class="hamburger hamburger--slider" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
Summary
react-burger-menu is a React-specific solution offering pre-built menu styles and animations, while hamburgers provides CSS-based hamburger icons that can be used in any project. react-burger-menu is more feature-rich for React applications but limited to that ecosystem, whereas hamburgers is more flexible and lightweight but requires additional implementation for full menu functionality.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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
- Download and include the CSS in the
<head>
of your site:
<link href="dist/hamburgers.css" rel="stylesheet">
- 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>
- 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.
- 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.
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.
- Import the
hamburgers.scss
file in your Sass manifest file:
@import "path/to/hamburgers";
- Customize your hamburger and/or remove any types you donât want in
hamburgers.scss
. - 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
- Add Hamburgers to your Gemfile.
gem 'hamburgers'
- Run
bundle install
. - 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.
Top Related Projects
jQuery contextMenu plugin & polyfill
:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot