forked from googlearchive/icon-transition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icon-transition.html
84 lines (72 loc) · 3 KB
/
icon-transition.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
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
`icon-transition` is an element allowing line-based SVG icons to seamlessly change from one to the other. It provides an implementation of Material Design's [delightful details](http://www.google.com/design/spec/animation/delightful-details.html) transitions.
Example:
<icon-transition id="icon1" on-mouseover="pickIcon" icon="plus" ></icon-transition>
<icon-transition id="icon2" on-mouseover="pickIcon" icon="check" ></icon-transition>
<script>
Polymer({
is: 'transition-demo',
pickIcon: function(e) {
this.icon = e.currentTarget.icon;
}
});
</script>
In the above example, we have two `<icon-transition>` icons whose transitions are specified in CSS. Hovering over the icon triggers a transition from one icon to the next.
@group Polymer Labs Elements
@element icon-transition
@homepage github.io
@contributors Tom Wiltzius, Addy Osmani, Nicholas Albion
-->
<link rel="import" href="bower_components/polymer/polymer.html">
<dom-module id="icon-transition">
<link rel="stylesheet" href="icon-transition.css">
<template>
<svg id="svg" viewbox="0 0 24 24" stroke$="{{color}}">
<g transform="translate(12, 12)">
<line x1="-1" y1="0" x2="1" y2="0"></line>
<line x1="-1" y1="0" x2="1" y2="0"></line>
<line x1="-1" y1="0" x2="1" y2="0"></line>
</g>
</svg>
</template>
<script>
Polymer({
is: 'icon-transition',
properties: {
/** Specify the stroke color of the current SVG icon */
_rotate: 0,
color: {
type: String,
value: '#000'
},
icon: {
type: String,
observer: 'iconChanged'
}
},
iconChanged: function() {
this._rotate += 180;
var cl = this.icon;
if ((this._rotate % 360) == 180) {
cl += ' rotate';
}
var svg = this.$.svg; // Polymer.dom(this.$.svg);
svg.setAttribute('class', cl);
var transform = 'rotate(' + this._rotate + 'deg)';
if (document.documentElement.style.transform !== undefined) {
svg.style.transform = transform;
} else {
svg.style.webkitTransform = transform;
}
}
});
</script>
</dom-module>