美味的CSS动画汉堡包:hamburgers_html/css_WEB-ITnose
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
- Customization
- Accessibility
- Browser Support
Usage
Download and include the CSS in the
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 class="hamburger" type="button"> <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--arrowhamburger--arrow-rhamburger--arrowalthamburger--arrowalt-rhamburger--boringhamburger--collapsehamburger--collapse-rhamburger--elastichamburger--elastic-rhamburger--emphatichamburger--emphatic-rhamburger--sliderhamburger--slider-rhamburger--spinhamburger--spin-rhamburger--squeezehamburger--vortexhamburger--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
I’ve also included .scss source files if you use Sass as your CSS precompiler. It’s customizable and modular.
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.
Hamburgers is also available on npm and Bower.
npm install hamburgersbower install css-hamburgers
* Be sure to run the CSS through Autoprefixer since the Sass doesn’t account for vendor prefixes.
Customization
Here is the full list of default settings (found in _sass/hamburgers/hamburgers.scss);
$hamburger-padding-x : 15px !default;$hamburger-padding-y : 15px !default;$hamburger-layer-width : 40px !default;$hamburger-layer-height : 4px !default;$hamburger-layer-spacing : 6px !default;$hamburger-layer-color : #000 !default;$hamburger-layer-border-radius : 4px !default;$hamburger-hover-opacity : 0.7 !default;$hamburger-hover-transition-duration : 0.15s !default;$hamburger-hover-transition-timing-function: linear !default;// 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 !default;$hamburger-hover-filter : opacity(50%) !default;
To override any default settings, you can change the value(s) within hamburgers.scss, but I recommend you declare your new settings separately:
@import "path/to/hamburgers";$hamburgers-padding-x: 20px;$hamburgers-padding-y: 15px;
You can also create a separate file (e.g. hamburgers-settings.scss) with those declarations, then import it along with Hamburgers:
@import "path/to/hamburgers";@import "hamburgers-settings"
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.
<button class="hamburger hamburger--elastic" type="button" aria-label="Menu" aria-controls="navigation"> <span class="hamburger-box"> <span class="hamburger-inner"></span> </span></button><nav id="navigation"> <!--navigation goes here--></nav>
If you insist on using
<div class="hamburger hamburger--elastic" tabindex="0" aria-label="Menu" role="button" aria-controls="navigation"> <div class="hamburger-box"> <div class="hamburger-inner"></div> </div></div><nav id="navigation"> <!--navigation goes here--></nav>
A label can 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.
项目地址: https://github.com/jonsuh/hamburgers

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati
