forked from codrops/ElasticSVGElements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhamburger.html
124 lines (112 loc) · 4.79 KB
/
hamburger.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
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Elastic SVG Elements | Menu Icon</title>
<meta name="description" content="Adding elasticity with SVG shape animations" />
<meta name="keywords" content="svg, morph, snap.svg, effect, animation, css, shape" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.2.0/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/hamburger.css" />
<script src="js/snap.svg-min.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="theme-6">
<div class="container">
<div class="main">
<header class="codrops-header">
<h1>Elastic SVG Elements <span>Adding elasticity with SVG shape animations</span></h1>
<div class="codrops-links">
<a class="codrops-icon codrops-icon-prev" href="http://tympanus.net/Development/DialogEffects/" title="Previous Demo"><span>Previous Demo</span></a> /
<a class="codrops-icon codrops-icon-drop" href="http://tympanus.net/codrops/?p=21555" title="Back to the article"><span>Back to the Codrops Article</span></a>
</div>
<nav class="codrops-demos">
<a href="index.html">Sidebar Menu</a>
<a href="pullupmenu.html">Pull-Up Menu</a>
<a href="dropdown.html">Drop-down Menu</a>
<a href="drag.html">Drag & Drop</a>
<a href="collapseexpand.html">Collapse & Expand</a>
<a class="current-demo" href="hamburger.html">Menu Icon</a>
<a href="circlemenu.html">Circular Menu</a>
<a href="inputs.html">Inputs</a>
<a href="button.html">Buttons</a>
</nav>
</header>
<button id="hamburger" class="menu-button">
<span id="morph-shape" class="morph-shape" data-morph-open="M3,20c0,0,12-4,27-4s27,4,27,4;M3,60c0,0,12,4,27,4s27-4,27-4" data-morph-close="M3,20c0,0,12,4,27,4s27-4,27-4;M3,60c0,0,12-4,27-4s27,4,27,4">
<svg width="100%" height="100%" viewBox="0 0 60 80" preserveAspectRatio="none">
<path d="M3,20c0,0,12,0,27,0s27,0,27,0"/>
<line x1="3" y1="40" x2="57" y2="40"/>
<path d="M3,60c0,0,12,0,27,0s27,0,27,0"/>
</svg>
</span>
</button>
<!-- Related demos -->
<section class="related">
<p>If you enjoyed this demo you might also like:</p>
<a href="http://tympanus.net/Development/WobblySlideshowEffect/">
<img src="img/related/WobblySlideshowEffect.png" />
<h3>Wobbly Slideshow Effect</h3>
</a>
<a href="http://tympanus.net/Tutorials/ShapeHoverEffectSVG/">
<img src="img/related/ShapeHoverEffect.png" />
<h3>Shape Hover Effect</h3>
</a>
</section>
</div><!-- /main -->
</div><!-- /container -->
<script src="js/classie.js"></script>
<script>
(function() {
function SVGHamburger( el, options ) {
this.el = el;
this.init();
}
SVGHamburger.prototype.init = function() {
this.shapeEl = this.el.querySelector( 'span.morph-shape' );
var s = Snap( this.shapeEl.querySelector( 'svg' ) );
this.pathEl1 = s.select( 'path:nth-of-type(1)' );
this.pathEl2 = s.select( 'path:nth-of-type(2)' );
this.paths = {
reset : {
path1 : this.pathEl1.attr( 'd' ),
path2 : this.pathEl2.attr( 'd' )
},
open : this.shapeEl.getAttribute( 'data-morph-open' ).split( ';' ),
close : this.shapeEl.getAttribute( 'data-morph-close' ).split( ';' )
};
this.isOpen = false;
this.initEvents();
};
SVGHamburger.prototype.initEvents = function() {
this.el.addEventListener( 'click', this.toggle.bind(this) );
};
SVGHamburger.prototype.toggle = function() {
var self = this,
paths = this.isOpen ? this.paths.close : this.paths.open;
if( self.isOpen ) {
setTimeout( function() { classie.remove( self.el, 'menu-button--open' ); }, 200 );
}
else {
setTimeout( function() { classie.add( self.el, 'menu-button--open' ); }, 200 );
}
this.pathEl1.stop().animate( { 'path' : paths[0] }, 300, mina.easeout, function() {
self.pathEl1.stop().animate( { 'path' : self.paths.reset.path1 }, 800, mina.elastic );
} );
this.pathEl2.stop().animate( { 'path' : paths[1] }, 300, mina.easeout, function() {
self.pathEl2.stop().animate( { 'path' : self.paths.reset.path2 }, 800, mina.elastic );
} );
this.isOpen = !this.isOpen;
};
new SVGHamburger( document.getElementById( 'hamburger' ) );
})();
</script>
</body>
</html>