-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.html
486 lines (441 loc) · 20.7 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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!doctype html>
<head>
<meta charset="utf-8">
<title>legitRipple.js - Demos and Docs</title>
<meta name="description" content="The legitRipple.js jQuery plugin's Demos and Documentation. A lightweight, CSS based jQuery plugin for material-design ripple effects.">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="https://matthias-vogt.github.io/legitRipple.js">
<link rel="stylesheet" href="css/ripple.css">
<!-- ^ using the uncompressed version for developement
In production, please use: <link rel="stylesheet" href="dist/ripple.min.css">
-->
<link rel="stylesheet" href="css/demo.css">
<!-- github ribbon -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.1.1/gh-fork-ribbon.min.css" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.1.1/gh-fork-ribbon.ie.min.css" />
<![endif]-->
<link rel="shortcut icon" type="image/x-icon" href="demo-media/favicon.png">
<link rel="apple-touch-icon" href="demo-media/apple-touch-icon.png">
</head>
<body>
<!--[if lte IE 9]>
<div class="browserupgrade">IE7, IE8 and IE9 aren't supported by this plugin. <a href="http://caniuse.com/#feat=css-transitions">Browser support</a></div>
<![endif]-->
<div id="fadeInOverlay">
<header>
<div class="maxWidthWrapper">
<h1>legitRipple.js</h1>
<p>A jQuery plugin for legit Material Design ripples.</p>
<p>It works with smooth <b>CSS transitions</b>, is totally <b>customizable</b> and <b><2kb</b> gzipped.</p>
<span>*clicky clicky*</span>
</div>
</header>
</div>
<div class="github-fork-ribbon-wrapper right">
<div class="github-fork-ribbon">
<a href="https://github.com/matthias-vogt/legitRipple.js">Fork me on GitHub</a>
</div>
</div>
<nav>
<!-- <ul>
<li><a href="#demos">Demos</a></li>
<li><a href="#usage">Usage</a>
<ul>
<li><a href="#options">Options</a></li>
<li><a href="#destroy-and-unbind">Destroy and unbind</a></li>
<li><a href="#custom-ripples">Custom ripples</a></li>
<li><a href="#custom-elements">Custom elements</a></li>
<li><a href="#custom-css">Custom CSS</a></li>
<li><a href="#manually-controlling-ripples">Manually controlling ripples</a></li>
<li><a href="#callback">Callback</a></li>
</ul>
</li>
<li><a href="#why">Why another ripple plugin?</a></li>
<li><a href="#browser-support">Browser support</a></li>
</ul> -->
<!-- inject:toc -->
<ul>
<li><a href="#usage">Usage</a>
<ul>
<li><a href="#install">Install</a></li>
<li><a href="#options">Options</a>
<ul>
<li><a href="#coming-soon">Coming soon</a></li>
</ul>
</li>
<li><a href="#destroying-unbinding-and-overwriting">Destroying, unbinding and overwriting</a></li>
<li><a href="#custom-ripples">Custom ripples</a>
<ul>
<li><a href="#custom-css">Custom CSS</a></li>
<li><a href="#custom-elements">Custom elements</a></li>
<li><a href="#manually-controlling-ripples">Manually controlling ripples</a></li>
</ul>
</li>
<li><a href="#callback">Callback</a></li>
</ul>
</li>
<li><a href="#touch-support">Touch support</a></li>
<li><a href="#motivation">Motivation</a></li>
<li><a href="#browser-support">Browser support</a></li>
</ul>
<!-- endinject -->
</nav>
<!-- <header>
<svg>
<defs>
<mask id="mask" >
<rect id="alpha"/>
<text id="title" dy="1em">Here's a lightweight, CSS-based approach</text>
<text id="title" dy="1em">to the material ripple-effect</text>
<text id="subtitle" dy="1em">It works with jQuery though ;)</text>
</mask>
</defs>
<rect id="base"/>
</svg>
</header> -->
<main>
<section id="demos-section">
<h2 id="demos">Demos</h2>
<div class="box levitate" id="demobox">
I'm a Box!
<p>Try to click and <b>hold/drag</b> to see the ripple effect respond</p>
</div>
<button class="levitate">Button</button>
<button class="flat">Flat Button</button>
<!--<button class="levitate">No drop effect</button>-->
<div id="dropdown-handle"></div>
<div class="box levitate longDrop longOpacity overflow" id="customRipple">
You can customize your ripples
<p>Custom elements, custom CSS, whatever you want.</p>
<aside>try holding for a long time</aside>
<video class="legitRipple-template" poster="demo-media/tumblr_nqotmoSJyx1ta8bfso1_500.gif" preload="none">
<source src="demo-media/ISS%20Video%20Resource_Earth_Views_720p.webmhd.webm#t=38" type="video/webm">
<source src="https://ia801004.us.archive.org/33/items/ISSVideoResourceEarthViews720p/ISS%20Video%20Resource_Earth_Views_720p.mp4#t=38" type="video/mp4">
</video>
<!-- sources: fuckyeahtrippysgifs.tumblr.com, archive.org/details/ISSVideoResourceEarthViews720p -->
</div>
<a href="#0" id="link">
Works on links and other <code>inline</code> elements <span>(most of the time…)</span>
</a>
<!--<div class="box levitate" id="zindex">
You can position the ripple-effect behind the parent contents too, using <code>z-index</code>
</div>-->
<div class="wrapper">
<span>Void elements (those that can't have child elements) need a wrapper for the effect to work.</span>
<img title src="demo-media/deer-album-cover-new.png" alt="album cover">
<!-- image courtesy of https://caliography.wordpress.com/2013/07/24/animals-like-us/ -->
</div>
<div class="box levitate" id="maxDiameter">
You can set a maxDiameter option for the ripple effect
<p><code>.ripple({ maxDiameter: 40px });</code></p>
<aside>If you set <code>scaleMode</code> to "proportional" and drag, though, the ripple will still get bigger.</aside>
</div>
<div class="box levitate" id="proportional">
<p>The plugin features two <code>scaleMode</code> options for dragging:</p>
<code>proportional</code>
<p>Scales the ripple proportional to the amount it was dragged.
<br>Will probably become bigger than its container.</p>
</div>
<div class="box levitate" id="fixed">
<p>…and</p>
<code>fixed</code>
<p>Don't scale and release ripple when dragging upwards.</p>
</div>
<div class="longDrop longOpacity box levitate" id="long">
You can even change the <code>transition-duration</code>s
<p>
…for longer or shorter ripple animations.
<br>
<br>
<code>transition-duration: .75s, .36s;</code>
</p>
</div>
<a href="#0" id="inlineBlockLink">This is an <code>inline-block</code> link</a>
<div class="longDrop box overflow" id="overflow">
Try this one to see overflow
<p>Notice how the ripple responds to the mouse position in the box</p>
</div>
<div class="longDrop overflow box" id="circle">
<span>
Works with circles
<br><code>.ripple({maxDiameter: "100%"});</code>
</span>
</div>
<div class="overflow box" data-text="Works on weird aspect ratios!">
<!-- <p>bleh</p> -->
</div>
</section>
<section id="docs">
<a href="https://github.com/matthias-vogt/legitRipple.js" class="clickMePlease">
<button class="levitate">Check it out on GitHub!</button>
</a>
<!-- inject:readme -->
<h2 id="usage">Usage</h2>
<p>legitRipple.js depends on <a href="https://jquery.com/">jQuery</a>, so make sure you have that loaded. When the DOM is ready, you can use it like this:</p>
<pre class="rainbow"><code data-language="javascript">//ripple with default options
$(".some, .elements").ripple();
</code></pre><br>
<pre class="rainbow"><code data-language="javascript">//ripple with custom options
$(".elements").ripple({
scaleMode: false,
maxDiameter: "100%"
});
</code></pre><br>
<p>You can also use alternative syntax if you have a lot of ripple elements with different options.</p>
<pre class="rainbow"><code data-language="javascript">$.ripple({
".material": {},
".material.circle": {maxDiameter: "100%"},
".customHTML": {template: $("<p/>").text("Custom ripple content!")},
".callback": {
callback: function($container, $ripple, posI, maxDiameter) {
//is called whenever the ripple's css properties change
}
}
});
</code></pre><br>
<p>You can't apply the ripple effect on <a href="//www.w3.org/TR/html-markup/syntax.html#void-element"><code>void elements</code></a> (those that can't have child elements; <code><img></code>, <code><input></code>, …). However, you can simply wrap them and apply the effect to the wrapper element.</p>
<h3 id="install">Install</h3>
<pre class="rainbow"><code data-language="html"><link href="stylesheet" type="text/css" href="ripple.min.css">
<script src="jquery.min.js"></script>
<script src="ripple.min.js"></script>
</code></pre><br>
<p>For better loading performance, I'd recommend loading the script as non-critical content (by putting the <code><script></code> and <code><style></code> tags at the end of the body tag). Please also consider concatenating it with your other dependencies.</p>
<p>Install and update easily using <a href="http://bower.io">bower</a>:</p>
<pre class="rainbow"><code data-language="sh">bower install --save legitripple
</code></pre><br>
<h3 id="options">Options</h3>
<table>
<thead>
<tr>
<th>Option</th>
<th>Description</th>
<th>Expected Input</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>maxDiameter</code></td>
<td>Gives the ripple a max-width. <code>adaptPos: true</code> requires this to be in %; can be any unit with <code>adaptPos: false</code>. 100% for circles.</td>
<td>Number with unit as <code>String</code> ("100%" or "3.125em")</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>dragging</code></td>
<td>Whether the ripple should be able to be dragged.</td>
<td><code>Boolean</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>adaptPos</code></td>
<td>Whether to take the mouse position relative to the ripple-container's dimensions into account when positioning the ripple. Note: <a href="#motivation">more info on "adaptPos"</a></td>
<td><code>Boolean</code></td>
<td><code>true</code></td>
</tr>
<tr>
<td><code>scaleMode</code></td>
<td>How to scale the ripple while dragging:<br><br><code>"proportional"</code>: Proportional to the amount it was dragged. Will probably become much bigger than its container.<br><br><code>"fixed"</code>: Don't scale and release ripple while dragging upwards.<br><br>falsey values: Don't scale while dragging</td>
<td><code>String</code> or falsey value</td>
<td><code>"fixed"</code></td>
</tr>
<tr>
<td><code>template</code></td>
<td>Set the HTML content of ripples. See: <a href="#custom-elements">custom ripple element</a>.</td>
<td><code>NodeList</code>, Element or <code>true</code> when the template is in the HTML markup</td>
<td><code>null</code></td>
</tr>
<tr>
<td><code>fixedPos</code></td>
<td>Gives the ripple a fixed position in the parent.</td>
<td><code>true</code> for centered position or <code>Array</code> with x- and y-coordinates relative to the parent's offset (e.g. <code>[20, 40]</code> = x: 20px, y: 40px)</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>allowDragging</code></td>
<td>HTML5 dragging is disabled on ripple elements by default for nicer interaction.</td>
<td><code>Boolean</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>unbind</code></td>
<td>When set, unbinds all of the ripple's event handlers. Doesn't remove any elements or classes. (see <a href="#destroying-unbinding-and-overwriting">Destroying, unbinding and overwriting</a>)</td>
<td><code>Boolean</code></td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>touchDelay</code></td>
<td>Time to delay triggering of ripples on touch devices (e.g. to enable scrolling past ripple elements without triggering ripples)</td>
<td>Time in ms as <code>number</code></td>
<td><code>100</code></td>
</tr>
<tr>
<td><code>callback</code></td>
<td>A function to be called each time the ripple element's style property changes</td>
<td><code>function</code></td>
<td><code>null</code></td>
</tr>
</tbody>
</table>
<h4 id="coming-soon">Coming soon</h4>
<table>
<thead>
<tr>
<th>Option</th>
<th>Description</th>
<th>Expected Input</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>rippleOnHover</code></td>
<td>Whether to use the ripple as a hover effect</td>
<td>Boolean</td>
<td><code>false</code></td>
</tr>
<tr>
<td><code>destination</code></td>
<td>An element other than the clicked one the ripple should travel to</td>
<td><code>NodeList</code>, Element or selector <code>String</code> or <code>Array</code> of coordinates in px</td>
<td><code>null</code></td>
</tr>
</tbody>
</table>
<h3 id="destroying-unbinding-and-overwriting">Destroying, unbinding and overwriting</h3>
<p>Ripples can be overwritten as you'd expect:</p>
<pre class="rainbow"><code data-language="javascript">$(".ripple").ripple();
$(".ripple.noScale").ripple({scaleMode: 0});
//.ripple has default options
//.ripple.noScale has default options and {scaleMode: 0}
$(".ripple.noScale").ripple({scaleMode: 0});
$(".ripple").ripple();
//.ripple and ripple.noScale have default options
</code></pre><br>
<p>You can also unbind event handlers from ripples or destroy all ripples.</p>
<pre class="rainbow"><code data-language="javascript">$(".ripple").ripple({unbind: true});
//removes all event handlers from a ripple element.
//if you call it during a ripple animation, the animation
//will still complete
$.ripple.destroy();
//stops any ripple animations in their tracks and removes any
//plugin created elements, classes and event bindings.
//calling .ripple() will still work
</code></pre><br>
<h3 id="custom-ripples">Custom ripples</h3>
<h4 id="custom-css">Custom CSS</h4>
<p>Ripples can be targeted using the <code>.legitRipple-ripple</code> class, their containers using <code>.legitRipple</code>. CSS selectors for ripples shouldn't be order-specific to target all ripples since there can be multiple ripples active in an element at once.</p>
<pre class="rainbow"><code data-language="css">.container .legitRipple-ripple {
background: yellow;
/* You can change the transition properties too!
Just don't try and change the width transition's easing. */
transition-duration: .15s, .9s; /*width, opacity*/
}
</code></pre><br>
<h4 id="custom-elements">Custom elements</h4>
<p>You can even use custom elements for ripples by setting the <code>template</code> option with an Element or <code>NodeList</code> as the value, like <code>template: $("<p/>").text("Look, ma, I'm custom!")</code>.</p>
<p>Alternatively, you can set the <code>template</code> option to <code>true</code> and add the following markup to your HTML:</p>
<pre class="rainbow"><code data-language="html"><div>
Container Element
<div class="legitRipple-template">Your custom element</div>
</div>
</code></pre><br>
<p>How the code will look when a ripple is triggered:</p>
<pre class="rainbow"><code data-language="html"><div class="legitRipple">
Container Element
<div class="legitRipple-template">Your custom element</div>
<span class="legitRipple-ripple legitRipple-custom">
<div>Your custom element</div>
</span>
</div>
</code></pre><br>
<p>The custom element is used as a template and will be hidden by CSS on load. When a ripple is triggered, the custom element will be <code>.clone()</code>'d, the <code>legitRipple-template</code> class removed and wrapped in a <code><span/></code> with a <code>legitRipple-ripple</code> class before being appended to the ripple container.</p>
<p>By default, when using custom ripple elements, each direct child of <code>.legitRipple-ripple</code> will be scaled up to cover the entire ripple container, like:</p>
<pre class="rainbow"><code data-language="css">.legitRipple-custom > * {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
transform: translate(-50%, -50%);
}
</code></pre><br>
<h4 id="manually-controlling-ripples">Manually controlling ripples</h4>
<p>Since ripple elements will only be removed on <code>transitionend</code>, adding <code>css opacity: 1 !important;</code> to their CSS will keep them alive forever.
If you want to remove these ripples later, just change the CSS via jQuery like:</p>
<pre class="rainbow"><code data-language="javascript">$(".ripple-element>.legitRipple-ripple").css("opacity", "0 !important");
</code></pre><br>
<p>Moreover, you can manually trigger ripples <a href="https://github.com/matthias-vogt/legitRipple.js/blob/gh-pages/js/demo.js#L69-L82">like in the demo</a> by faking mousedown/touchstart events and do some <a href="http://codepen.io/matze/pen/PPJxyr">crazy stuff</a> with it.</p>
<h3 id="callback">Callback</h3>
<p>For the callback option, you can pass a function which is called everytime the ripple's style attribute changes.</p>
<pre class="rainbow"><code data-language="javascript">$(".elements").ripple({callback: function($container, $ripple, posI, maxDiameter) {
/* $container: The ripple container element
$ripple: The ripple element
posI: An array with two indices (0 <= i <= 1) for the
x- and y-position of the ripple relative to the parent
maxDiameter: A string with the max-width of the ripple
element with unit ("120%", "10em", …)
*/
}});
</code></pre><br>
<h2 id="touch-support">Touch support</h2>
<p>legitRipple.js has full touch support. You can even use multi-touch for multiple ripples in different elements at the same time.</p>
<!-- endinject -->
</section>
<!--
<h2 id="Try <em>all the options!</em>">Try <em>all the options!</em></h2>
<section id="cards-section">
<div class="levitate">awd</div>
<div class="levitate"></div>
<div class="levitate"></div>
</section>
-->
<section id="why-section">
<h2 id="motivation">Motivation</h2>
<p>On android, the ripples don't spread in all directions equally as fast. They're positioned relative to the touch position as the touch position is positioned relative to the ripple's container.</p>
<div class="container">
<video loop autoplay>
<source src="demo-media/reference-1.webm" type="video/webm">
<source src="demo-media/reference-1.mp4" type="video/mp4">
</video>
</div>
<div class="container">
<video loop autoplay>
<source src="demo-media/reference-2.webm" type="video/webm">
<source src="demo-media/reference-2.mp4" type="video/mp4">
</video>
</div>
<aside>App courtesy of <a href="https://play.google.com/store/apps/details?id=com.sonyericsson.music">Music</a> and <a href="https://play.google.com/store/apps/details?id=com.kabouzeid.gramophone">Phonograph Music Player</a></aside>
<br>
<div class="levitate overflow" id="v1">{ adaptPos: true }</div>
<div class="levitate overflow" id="v2">{ adaptPos: false }</div>
<p>There are <em><a href="https://github.com/search?l=JavaScript&q=material+ripple&type=Repositories">a lot</a></em> of similar plugins out there but this effect, hadn't been replicated in any of them AFAIK (which is not surprising since it's not documented in <a href="https://www.google.com/design/spec/animation/responsive-interaction.html">Google's Material Design spec</a> either), so I decided to make my own.</p>
<p>Adding to the incentive was that the plugins I saw don't slow the ripple spread on mousedown and speed it up again on mouseup or don't have dragging or touch support implemented correctly.</p>
<p>legitRipple.js is probably also the only one which works with inline elements and has ripples with customizable HTML.</p>
<p>Maybe it's a bit overkill for this simple effect but that's your call to decide ;)</p>
</section>
<section id="support-section">
<h2 id="browser-support">Browser support</h2>
<p>This uses CSS3 transitions, so <a href="http://caniuse.com/#feat=css-transitions">browser support</a> is ie10+</p>
</section>
</section>
</main>
<footer>
<div class="maxWidthWrapper">
Made by <a href="https://github.com/matthias-vogt">Matthias Vogt</a>
<br>
<a href="https://github.com/matthias-vogt/legitRipple.js">Download and contribute on GitHub!</a>
</div>
</footer>
<script src="demo-media/libs/jquery-2.1.4.min.js"></script>
<script src="js/ripple.js"></script>
<!-- ^ using the uncompressed version for developement
In production, please use: <script src="dist/ripple.min.js"></script>
-->
<script src="js/demo.js"></script>
<!-- syntax highlighting -->
<script src="demo-media/libs/rainbow-custom.min.js"></script>
<link rel="stylesheet" property="stylesheet" href="demo-media/libs/github.css">
<!-- property="stylesheet" to fight validation errors https://stackoverflow.com/questions/18549726/ -->
</body>