目錄
Table of Contents
Usage
Sass
Customization
ems or rems
Not satisfied?
Accessibility
Browser Support
首頁 web前端 html教學 美味的CSS动画汉堡包:hamburgers_html/css_WEB-ITnose

美味的CSS动画汉堡包:hamburgers_html/css_WEB-ITnose

Jun 21, 2016 am 08:55 AM

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

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

    <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.

  • 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.

    <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

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

    <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

    本網站聲明
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

    熱門文章

    倉庫:如何復興隊友
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island冒險:如何獲得巨型種子
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
    1 週前 By 尊渡假赌尊渡假赌尊渡假赌

    熱門文章

    倉庫:如何復興隊友
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island冒險:如何獲得巨型種子
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
    1 週前 By 尊渡假赌尊渡假赌尊渡假赌

    熱門文章標籤

    記事本++7.3.1

    記事本++7.3.1

    好用且免費的程式碼編輯器

    SublimeText3漢化版

    SublimeText3漢化版

    中文版,非常好用

    禪工作室 13.0.1

    禪工作室 13.0.1

    強大的PHP整合開發環境

    Dreamweaver CS6

    Dreamweaver CS6

    視覺化網頁開發工具

    SublimeText3 Mac版

    SublimeText3 Mac版

    神級程式碼編輯軟體(SublimeText3)

    公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗? 公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗? Mar 04, 2025 pm 12:32 PM

    公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?

    如何使用HTML5表單驗證屬性來驗證用戶輸入? 如何使用HTML5表單驗證屬性來驗證用戶輸入? Mar 17, 2025 pm 12:27 PM

    如何使用HTML5表單驗證屬性來驗證用戶輸入?

    如何高效地在網頁中為PNG圖片添加描邊效果? 如何高效地在網頁中為PNG圖片添加描邊效果? Mar 04, 2025 pm 02:39 PM

    如何高效地在網頁中為PNG圖片添加描邊效果?

    &lt; iframe&gt;的目的是什麼。 標籤?使用時的安全考慮是什麼? &lt; iframe&gt;的目的是什麼。 標籤?使用時的安全考慮是什麼? Mar 20, 2025 pm 06:05 PM

    &lt; iframe&gt;的目的是什麼。 標籤?使用時的安全考慮是什麼?

    使用IFRAME的安全性含義是什麼?如何減輕它們? 使用IFRAME的安全性含義是什麼?如何減輕它們? Mar 18, 2025 pm 02:51 PM

    使用IFRAME的安全性含義是什麼?如何減輕它們?

    我如何使用html5&lt; meter&gt; 要在範圍內顯示數值數據的元素? 我如何使用html5&lt; meter&gt; 要在範圍內顯示數值數據的元素? Mar 12, 2025 pm 04:08 PM

    我如何使用html5&lt; meter&gt; 要在範圍內顯示數值數據的元素?

    HTML5中跨瀏覽器兼容性的最佳實踐是什麼? HTML5中跨瀏覽器兼容性的最佳實踐是什麼? Mar 17, 2025 pm 12:20 PM

    HTML5中跨瀏覽器兼容性的最佳實踐是什麼?

    如何有效地使用HTML鏈接進行導航和SEO? 如何有效地使用HTML鏈接進行導航和SEO? Mar 18, 2025 pm 02:39 PM

    如何有效地使用HTML鏈接進行導航和SEO?

    See all articles