forked from codrops/ElasticSVGElements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.html
190 lines (177 loc) · 8.64 KB
/
inputs.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
<!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 | Form Inputs</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/inputs.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-7">
<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 href="hamburger.html">Menu Icon</a>
<a href="circlemenu.html">Circular Menu</a>
<a class="current-demo" href="inputs.html">Inputs</a>
<a href="button.html">Buttons</a>
</nav>
</header>
<div class="content">
<div class="input-container">
<label class="input-label" for="input-1">Your name</label>
<div class="input-wrap">
<input type="text" id="input-1" />
<span class="morph-shape" data-morph-active="M359,70c0,0-59,0-174,0C84,70,9,70,9,70s5-10,5-30c0-16-5-30-5-30s75,0,176,0c115,0,174,0,174,0s-5,14-5,30
C354,60,359,70,359,70z">
<svg width="100%" height="100%" viewBox="0 0 370 80" preserveAspectRatio="none">
<path d="M359,70c0,0-59,0-174,0C84,70,9,70,9,70s0-10,0-30c0-16,0-30,0-30s75,0,176,0c115,0,174,0,174,0s0,14,0,30C359,60,359,70,359,70z"/>
</svg>
</span>
</div>
<br />
<label class="input-label" for="input-2">Your email</label>
<div class="input-wrap">
<input type="text" id="input-2"/>
<span class="morph-shape" data-morph-active="M359,70c0,0-59,6-174,6C84,76,9,70,9,70S3,60,3,40c0-16,6-30,6-30s75-6,176-6c115,0,174,6,174,6s8,14,8,30C367,60,359,70,359,70z">
<svg width="100%" height="100%" viewBox="0 0 370 80" preserveAspectRatio="none">
<path d="M359,70c0,0-59,0-174,0C84,70,9,70,9,70s0-10,0-30c0-16,0-30,0-30s75,0,176,0c115,0,174,0,174,0s0,14,0,30C359,60,359,70,359,70z"/>
</svg>
</span>
</div>
</div>
<h2 class="note">Click, hold & release:</h2>
<div class="input-container input-container--indent">
<div class="input-wrap input-wrap--small">
<input type="checkbox" id="checkbox-1" />
<i class="fa fa-fw fa-check"></i>
<span class="morph-shape" data-morph-active="M273,273c0,0-55.8,24-123,24c-78.2,0-123-24-123-24S3,235.3,3,150C3,79.936,27,27,27,27S72,3,150,3c85,0,123,24,123,24s24,38.43,24,123C297,229.646,273,273,273,273z">
<svg width="100%" height="100%" viewBox="0 0 300 300" preserveAspectRatio="none">
<path d="M273,273c0,0-55.8,0-123,0c-78.2,0-123,0-123,0s0-37.7,0-123c0-70.064,0-123,0-123s45,0,123,0c85,0,123,0,123,0s0,38.43,0,123C273,229.646,273,273,273,273z"/>
</svg>
</span>
</div>
<label class="input-label input-label--long" for="checkbox-1">Receive notifications</label>
</div>
<div class="input-container input-container--indent">
<div class="input-wrap input-wrap--small">
<input type="checkbox" id="checkbox-2" />
<i class="fa fa-fw fa-check"></i>
<span class="morph-shape" data-morph-active="M273,273c0,0-55.8,24-123,24c-78.2,0-123-24-123-24S3,235.3,3,150C3,79.936,27,27,27,27S72,3,150,3c85,0,123,24,123,24s24,38.43,24,123C297,229.646,273,273,273,273z">
<svg width="100%" height="100%" viewBox="0 0 300 300" preserveAspectRatio="none">
<path d="M273,273c0,0-55.8,0-123,0c-78.2,0-123,0-123,0s0-37.7,0-123c0-70.064,0-123,0-123s45,0,123,0c85,0,123,0,123,0s0,38.43,0,123C273,229.646,273,273,273,273z"/>
</svg>
</span>
</div>
<label class="input-label input-label--long" for="checkbox-2">Allow email alerts</label>
</div>
<div class="input-container input-container--indent input-container--space">
<div class="input-wrap input-wrap--small">
<input type="radio" id="radio-1" name="radiogroup" />
<i class="fa fa-fw fa-circle"></i>
<span class="morph-shape" data-morph-active="M251,150c0,71.797-29.203,149-101,149S49,221.797,49,150S78.203,1,150,1S251,78.203,251,150z">
<svg width="100%" height="100%" viewBox="0 0 300 300" preserveAspectRatio="none">
<path d="M281,150c0,71.797-59.203,131-131,131S19,221.797,19,150S78.203,19,150,19S281,78.203,281,150z"/>
</svg>
</span>
</div>
<label class="input-label input-label--long" for="radio-1">Newsletter digest</label>
</div>
<div class="input-container input-container--indent">
<div class="input-wrap input-wrap--small">
<input type="radio" id="radio-2" name="radiogroup" />
<i class="fa fa-fw fa-circle"></i>
<span class="morph-shape" data-morph-active="M251,150c0,71.797-29.203,149-101,149S49,221.797,49,150S78.203,1,150,1S251,78.203,251,150z">
<svg width="100%" height="100%" viewBox="0 0 300 300" preserveAspectRatio="none">
<path d="M281,150c0,71.797-59.203,131-131,131S19,221.797,19,150S78.203,19,150,19S281,78.203,281,150z"/>
</svg>
</span>
</div>
<label class="input-label input-label--long" for="radio-2">Daily newsletters</label>
</div>
</div>
<!-- Related demos -->
<section class="related">
<p>If you enjoyed this demo you might also like:</p>
<a href="http://tympanus.net/Development/AnimatedCheckboxes/">
<img src="img/related/AnimatedCheckboxes.png" />
<h3>Animated Checkboxes</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 SVGInput( el, options ) {
this.el = el;
this.inputEl = this.el.querySelector( 'input' );
this.init();
}
SVGInput.prototype.init = function() {
this.shapeEl = this.el.querySelector( 'span.morph-shape' );
var s = Snap( this.shapeEl.querySelector( 'svg' ) );
this.pathEl = s.select( 'path' );
this.paths = {
reset : this.pathEl.attr( 'd' ),
active : this.shapeEl.getAttribute( 'data-morph-active' )
};
this.initEvents();
};
SVGInput.prototype.initEvents = function() {
if( this.inputEl.type === 'checkbox' || this.inputEl.type === 'radio' ) {
this.el.addEventListener( 'mousedown', this.down.bind(this) );
this.el.addEventListener( 'touchstart', this.down.bind(this) );
this.el.addEventListener( 'mouseup', this.up.bind(this) );
this.el.addEventListener( 'touchend', this.up.bind(this) );
this.el.addEventListener( 'mouseout', this.up.bind(this) );
}
else {
this.el.addEventListener( 'click', this.toggle.bind(this) );
}
};
SVGInput.prototype.down = function() {
this.pathEl.stop().animate( { 'path' : this.paths.active }, 150, mina.easein );
};
SVGInput.prototype.up = function() {
this.pathEl.stop().animate( { 'path' : this.paths.reset }, 1000, mina.elastic );
};
SVGInput.prototype.toggle = function() {
var self = this;
this.pathEl.stop().animate( { 'path' : this.paths.active }, 200, mina.easein, function() {
self.pathEl.stop().animate( { 'path' : self.paths.reset }, 600, mina.elastic );
} );
};
[].slice.call( document.querySelectorAll( '.input-wrap' ) ).forEach( function( el ) {
new SVGInput( el );
} );
})();
</script>
</body>
</html>