blob: a4bd7bea2dcd3977114cb47277b74380cbd590ab (
plain)
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
|
============================================
Animation inspector example: CSS transitions
============================================
Firefox Logo Animation
**********************
Example animation using `CSS transitions <https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions>`_.
HTML Content
------------
.. code-block:: html
<div class="channel">
<img src="developer.png" class="icon"/>
<span class="note">Firefox Developer Edition</span>
</div>
CSS Content
-----------
.. code-block:: css
.channel {
padding: 2em;
margin: 0.5em;
box-shadow: 1px 1px 5px #808080;
margin: 1.5em;
}
.channel > * {
vertical-align: middle;
line-height: normal;
}
.icon {
width: 50px;
height: 50px;
filter: grayscale(100%);
transition: transform 750ms ease-in, filter 750ms ease-in-out;
}
.note {
margin-left: 1em;
font: 1.5em "Open Sans",Arial,sans-serif;
overflow: hidden;
white-space: nowrap;
display: inline-block;
opacity: 0;
width: 0;
transition: opacity 500ms 150ms, width 500ms 150ms;
}
.icon#selected {
filter: grayscale(0%);
transform: scale(1.5);
}
.icon#selected+span {
opacity: 1;
width: 300px;
}
JavaScript Content
------------------
.. code-block:: JavaScript
function toggleSelection(e) {
if (e.button != 0) {
return;
}
if (e.target.classList.contains("icon")) {
var wasSelected = (e.target.getAttribute("id") == "selected");
clearSelection();
if (!wasSelected) {
e.target.setAttribute("id", "selected");
}
}
}
function clearSelection() {
var selected = document.getElementById("selected");
if (selected) {
selected.removeAttribute("id");
}
}
document.addEventListener("click", toggleSelection);
|