美味的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:


登录后复制

立即学习“前端免费学习笔记(深入)”;

Add the base hamburger markup:

登录后复制

You can use

s if you insist, but they’re not accessible as a menu button.

登录后复制

Append the class name of the type of hamburger you’re craving:

登录后复制

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:

登录后复制

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.

Download and unzip the source files. 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!

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.

登录后复制

If you insist on using

s, by default they’re not focusable (i.e. via keyboard or assistive technology). Add the tabindex attribute alongside ARIA.

登录后复制

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

登录后复制

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3116750.html

(0)
上一篇 2025年3月29日 13:21:02
下一篇 2025年3月29日 13:21:07

AD推荐 黄金广告位招租... 更多推荐

发表回复

登录后才能评论