forked from jonsuh/hamburgers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
407 lines (373 loc) · 23.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hamburgers by Jonathan Suh</title>
<link rel="stylesheet" href="css/screen.css">
<link rel="canonical" href="https://jonsuh.com/hamburgers/">
<meta name="robots" content="ALL">
<meta name="author" content="Jonathan Suh">
<link rel="author" href="https://jonsuh.com/">
<meta name="description" content="Tasty CSS-animated Hamburgers">
<meta http-equiv="content-language" content="en-us">
<meta property="og:locale" content="en_us">
<meta property="og:title" content="Hamburgers">
<meta property="og:url" content="https://jonsuh.com/hamburgers/">
<meta property="og:site_name" content="Jonathan Suh">
<meta property="og:type" content="website">
<meta property="og:description" content="Tasty CSS-animated Hamburgers">
<meta property="og:image" content="https://jonsuh.com/hamburgers/hamburger.png">
<meta property="fb:admins" content="506470591">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@jonsuh">
<meta name="twitter:creator" content="@jonsuh">
<meta name="twitter:url" content="https://jonsuh.com/hamburgers/">
<meta name="twitter:title" content="Hamburgers">
<meta name="twitter:description" content="Tasty CSS-animated Hamburgers">
<meta name="twitter:image:src" content="https://jonsuh.com/hamburgers/hamburger.png">
<meta name="theme-color" content="#2196f3">
<meta name="msapplication-TileColor" content="#2196f3">
</head>
<body>
<header class="header" role="banner">
<div class="header-logo">
<div data-class="0" class="hamburger hamburger--header">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
<span class="header-text"><span class="header-text-h">h</span>amburgers</span>
</div>
</header>
<main class="main" role="main">
<section class="section section--information">
<h1>Tasty CSS-animated hamburgers</h1>
<span class="information-directions">Click (or tap) each one to see it animate.</span>
</section>
<section class="table">
<div class="tray">
<div class="name">Slider</div>
<div class="hamburger hamburger--slider js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Squeeze</div>
<div class="hamburger hamburger--squeeze js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Arrow</div>
<div class="hamburger hamburger--arrow js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Arrow Alt</div>
<div class="hamburger hamburger--arrowalt js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Spin</div>
<div class="hamburger hamburger--spin js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Elastic</div>
<div class="hamburger hamburger--elastic js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Emphatic</div>
<div class="hamburger hamburger--emphatic js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Collapse</div>
<div class="hamburger hamburger--collapse js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Vortex</div>
<div class="hamburger hamburger--vortex js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Stand</div>
<div class="hamburger hamburger--stand js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Spring</div>
<div class="hamburger hamburger--spring js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">3DX</div>
<div class="hamburger hamburger--3dx js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">3DY</div>
<div class="hamburger hamburger--3dy js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray">
<div class="name">Boring</div>
<div class="hamburger hamburger--boring js-hamburger">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</div>
<div class="tray tray--empty"></div>
</section>
<section class="section section--usage">
<div class="content">
<h2 id="usage">Usage</h2>
<p>Using Hamburgers for your site is easy (well, that was my intention anyway).
<ol>
<li>
<p><a href="https://github.com/jonsuh/hamburgers">Download</a> and include the CSS in the <code><head></code> of your site:</p>
<pre class="highlight"><code><span class="nt"><link</span> <span class="na">href=</span><span class="s">"dist/hamburgers.css"</span> <span class="na">rel=</span><span class="s">"stylesheet"</span><span class="nt">></span>
</code></pre>
</li>
<li>
<p>Add the base hamburger markup:</p>
<pre class="highlight"><code><span class="nt"><button</span> <span class="na">class=</span><span class="s">"hamburger"</span> <span class="na">type=</span><span class="s">"button"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></span></span>
<span class="nt"></span></span>
<span class="nt"></button></span>
</code></pre>
<p>You <em>can</em> use <code><div></code>s (if you insist), but they’re not <a href="#accessibility">accessible</a> as a menu button.</p>
<pre class="highlight"><code><span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger"</span>></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
</code></pre>
</li>
<li>
<p>Append the class name of the type of hamburger you’re craving:
<pre class="highlight"><code><span class="nt"><button</span> <span class="na">class=</span><span class="s">"hamburger hamburger--collapse"</span> <span class="na">type=</span><span class="s">"button"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></span></span>
<span class="nt"></span></span>
<span class="nt"></button></span>
</code></pre>
</p>
<p>Here’s the list of hamburger-type classes you can choose from:</p>
<ul class="types">
<li><code>hamburger--3dx</code></li>
<li><code>hamburger--3dx-r</code></li>
<li><code>hamburger--3dy</code></li>
<li><code>hamburger--3dy-r</code></li>
<li><code>hamburger--arrow</code></li>
<li><code>hamburger--arrow-r</code></li>
<li><code>hamburger--arrowalt</code></li>
<li><code>hamburger--arrowalt-r</code></li>
<li><code>hamburger--boring</code></li>
<li><code>hamburger--collapse</code></li>
<li><code>hamburger--collapse-r</code></li>
<li><code>hamburger--elastic</code></li>
<li><code>hamburger--elastic-r</code></li>
<li><code>hamburger--emphatic</code></li>
<li><code>hamburger--emphatic-r</code></li>
<li><code>hamburger--slider</code></li>
<li><code>hamburger--slider-r</code></li>
<li><code>hamburger--spin</code></li>
<li><code>hamburger--spin-r</code></li>
<li><code>hamburger--spring</code></li>
<li><code>hamburger--spring-r</code></li>
<li><code>hamburger--stand</code></li>
<li><code>hamburger--stand-r</code></li>
<li><code>hamburger--squeeze</code></li>
<li><code>hamburger--vortex</code></li>
<li><code>hamburger--vortex-r</code></li>
</ul>
<p>Note: <code>-r</code> classes are reverse variants (e.g. <code>hamburger--spin</code> spins clockwise whereas <code>hamburger--spin-r</code> spins counterclockwise.</p>
</li>
<li>
<p>Trigger the active state by appending class name <code>is-active</code>:
<pre class="highlight"><code><span class="nt"><button</span> <span class="na">class=</span><span class="s">"hamburger hamburger--collapse is-active"</span> <span class="na">type=</span><span class="s">"button"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></span></span>
<span class="nt"></span></span>
<span class="nt"></button></span>
</code></pre>
<p>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. <a class="js-hint">Stuck? Here‘s a hint.</a></p>
<div id="hint" class="hint">
<br>
<p>Here’s a snippet of how to toggle a class name on click with JavaScript:</p>
<pre class="highlight"><code><span class="o"><</span><span class="nx">script</span><span class="o">></span>
<span class="c1">// Look for .hamburger</span>
<span class="kd">var</span> <span class="nx">hamburger</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">(</span><span class="s2">".hamburger"</span><span class="p">);</span>
<span class="c1">// On click</span>
<span class="nx">hamburger</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"click"</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="c1">// Toggle class "is-active"</span>
<span class="nx">hamburger</span><span class="p">.</span><span class="nx">classList</span><span class="p">.</span><span class="nx">toggle</span><span class="p">(</span><span class="s2">"is-active"</span><span class="p">);</span>
<span class="c1">// Do something else, like open/close menu</span>
<span class="p">});</span>
<span class="o"><</span><span class="sr">/script</span><span class="err">>
</span></code></pre>
<p>...or jQuery:</p>
<pre class="highlight"><code><span class="o"><</span><span class="nx">script</span><span class="o">></span>
<span class="kd">var</span> <span class="nx">$hamburger</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">".hamburger"</span><span class="p">);</span>
<span class="nx">$hamburger</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">"click"</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$hamburger</span><span class="p">.</span><span class="nx">toggleClass</span><span class="p">(</span><span class="s2">"is-active"</span><span class="p">);</span>
<span class="c1">// Do something else, like open/close menu</span>
<span class="p">});</span>
<span class="o"><</span><span class="sr">/script</span><span class="err">>
</span></code></pre>
</div>
</li>
</ol>
<h2 id="sass">Sass</h2>
<p>I’ve also included <code>.scss</code> source files if you use Sass as your CSS precompiler. It’s customizable and modular.</p>
<video controls>
<source src="customize.mp4" type="video/mp4">
<source src="customize.ogg" type="video/ogg">
<source src="customize.webm" type="video/webm">
</video>
<ol>
<li>
<p>Download and unzip the <a href="https://github.com/jonsuh/hamburgers">source code from Github</a>.</p>
</li>
<li>
<p>Copy the files from the <code>_sass/hamburgers</code> directory into your project.</p>
</li>
<li>
<p>Import the <code>hamburgers.scss</code> file in your Sass manifest file:</p>
<pre class="highlight"><code><span class="k">@import</span> <span class="s2">"path/to/hamburgers"</span><span class="p">;</span>
</code></pre>
</li>
<li>
<p>Customize your hamburger and/or remove any types you don’t want in <code>hamburgers.scss</code>.</p>
</li>
<li>
<p>Compile your Sass*, and voila!</p>
</li>
</ol>
<p>Hamburgers is also available on <a href="https://www.npmjs.com/package/hamburgers">npm</a> and <a href="http://bower.io/search/?q=css-hamburgers">Bower</a>.</p>
<pre class="highlight">
npm install hamburgers
bower install css-hamburgers
</pre>
<p><small>* Be sure to run the CSS through <a href="https://github.com/postcss/autoprefixer">Autoprefixer</a> since the Sass doesn’t account for vendor prefixes.</small></p>
<h3 id="customization">Customization</h3>
<p>Here is the full list of default settings (found in <code>_sass/hamburgers/hamburgers.scss</code>);</p>
<pre class="highlight"><code><span class="nv">$hamburger-padding-x</span> <span class="p">:</span> <span class="m">15px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-padding-y</span> <span class="p">:</span> <span class="m">15px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-layer-width</span> <span class="p">:</span> <span class="m">40px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-layer-height</span> <span class="p">:</span> <span class="m">4px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-layer-spacing</span> <span class="p">:</span> <span class="m">6px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-layer-color</span> <span class="p">:</span> <span class="mh">#000</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-layer-border-radius</span> <span class="p">:</span> <span class="m">4px</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-hover-opacity</span> <span class="p">:</span> <span class="m">0</span><span class="mi">.7</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-hover-transition-duration</span> <span class="p">:</span> <span class="m">0</span><span class="mi">.15s</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-hover-transition-timing-function</span><span class="p">:</span> <span class="n">linear</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="c1">// 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.
</span><span class="nv">$hamburger-hover-use-filter</span><span class="p">:</span> <span class="bp">false</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
<span class="nv">$hamburger-hover-filter</span> <span class="p">:</span> <span class="nf">opacity</span><span class="p">(</span><span class="m">50%</span><span class="p">)</span> <span class="o">!</span><span class="nb">default</span><span class="p">;</span>
</code></pre>
<p>To override any default settings, you can change the value(s) within <code>hamburgers.scss</code>, but I recommend you declare your new settings separately:</p>
<pre class="highlight"><code><span class="k">@import</span> <span class="s2">"path/to/hamburgers"</span><span class="p">;</span>
<span class="nv">$hamburgers-padding-x</span><span class="p">:</span> <span class="m">20px</span><span class="p">;</span>
<span class="nv">$hamburgers-padding-y</span><span class="p">:</span> <span class="m">15px</span><span class="p">;</span>
</code></pre>
<p>You can also create a separate file (e.g. hamburgers-settings.scss) with those declarations, then import it along with Hamburgers:</p>
<pre class="highlight"><code><span class="k">@import</span> <span class="s2">"path/to/hamburgers"</span><span class="p">;</span>
<span class="k">@import</span> <span class="s2">"hamburgers-settings"</span>
</code></pre>
<h3><code>ems</code> or <code>rems</code></h3>
<p>Wanna work with <code>ems</code> or <code>rems</code> instead of <code>px</code>? Just change all the <code>px</code> values to the unit of your choice. Note: Be consistent (all <code>px</code> or all <code>ems</code>), otherwise it may break—the math behind the customization will fail if it attempts to perform operations with values of different units.</p>
<h3>Not satisfied?</h3>
<p>Dig into <code>_base.scss</code> or <code>types/</code> and customize to your heart’s content. Fair warning: It‘s pretty delicate and may break, especially if you tweak the animations themselves.</p>
<h2 id="accessibility">Accessibility</h2>
<p>Hamburger menu icons can be useful in the right context, but they’re not the most accessible.</p>
<p>ARIA will help make it accessible to people with disabilities.</p>
<pre class="highlight"><code><span class="nt"><button</span> <span class="na">class=</span><span class="s">"hamburger hamburger--elastic"</span> <span class="na">type=</span><span class="s">"button"</span>
<span class="na">aria-label=</span><span class="s">"Menu"</span> <span class="na">aria-controls=</span><span class="s">"navigation"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></span></span>
<span class="nt"></span></span>
<span class="nt"></button></span>
<span class="nt"><nav</span> <span class="na">id=</span><span class="s">"navigation"</span><span class="nt">></span>
<span class="c"><!--navigation goes here--></span>
<span class="nt"></nav></span>
</code></pre>
<p>If you insist on using <code><div></code>s, by default they’re not focusable (i.e. via keyboard or assistive technology). Add the <code>tabindex</code> attribute alongside ARIA.</p>
<pre class="highlight"><code><span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger hamburger--elastic"</span> <span class="na">tabindex=</span><span class="s">"0"</span>
<span class="na">aria-label=</span><span class="s">"Menu"</span> <span class="na">role=</span><span class="s">"button"</span> <span class="na">aria-controls=</span><span class="s">"navigation"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger-box"</span><span class="nt">></span>
<span class="nt"><div</span> <span class="na">class=</span><span class="s">"hamburger-inner"</span><span class="nt">></div></span>
<span class="nt"></div></span>
<span class="nt"></div></span>
<span class="nt"><nav</span> <span class="na">id=</span><span class="s">"navigation"</span><span class="nt">></span>
<span class="c"><!--navigation goes here--></span>
<span class="nt"></nav></span>
</code></pre>
<p>A label can help make it more obvious that it toggles a menu.</p>
<div class="hamburger-wrap">
<button class="hamburger hamburger--collapse hamburger--accessible js-hamburger" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
<span class="hamburger-label">Menu</span>
</button>
</div>
<br>
<p>Here are <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA">some</a> <a href="https://webaccessibility.withgoogle.com/course">resources</a> on <a href="http://a11yproject.com/">web</a> <a href="http://www.html5accessibility.com/">accessibility</a> and <a href="https://w3c.github.io/aria-in-html/">ARIA</a>.</p>
<h2>Browser Support</h2>
<p>Animations use CSS3 3D transforms (<code>translate3d</code> 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 <a href="http://caniuse.com/#search=translate3d">caniuse.com</a>.</p>
</div>
</section>
</main>
<footer class="footer" role="contentinfo">
Chef <a href="https://jonsuh.com">Jonathan Suh</a>, <a href="https://twitter.com/jonsuh">@jonsuh</a><br><span class="footer-separator">|</span><a href="https://github.com/jonsuh/hamburgers">Recipe on Github</a>
</footer>
<script src="js/hamburgers.js" async></script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-2018785-1', 'auto');ga('send', 'pageview');</script>
</body>
</html>