aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/fx/css3/transition.html
blob: ae4eb0a4c0d300f40de43e7e0b5de30211d72ca9 (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
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
<!DOCTYPE html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<html>
<head>
<title>Closure: CSS3 Transition Demo</title>
<script src="../../../base.js"></script>
<script src="../../../deps.js"></script>
<link rel="stylesheet" href="../../css/demo.css">
<style>
.demo-options {
  float: left;
  padding: 0 0 20px;
  width: 248px;
}
.demo-panel {
  margin: 0 0 0 264px;
  padding: 80px 0 0 80px;
  text-align: center;
}
label.options {
  padding-left: 35px;
}
#demo-animated-box {
  background-color: #000;
  color: white;
  height: 20px;
  padding: 40px 0;
  text-align: center;
  width: 100px;
}
#demo-buttons {
  padding: 8px 0 0;
  text-align: center;
}
.goog-debug-panel {
  clear: both;
}
.goog-debug-panel .logdiv {
  height: 300px;
}
</style>

<script type="text/javascript">
goog.require('goog.debug.DivConsole');
goog.require('goog.debug.Logger');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.ActionHandler');
goog.require('goog.events.ActionHandler.EventType');
goog.require('goog.fx.Transition.EventType');
goog.require('goog.fx.css3');
</script>
</head>
<body>
<div class="demo-options">
<form>
  <fieldset>
    <legend>CSS3 transition choices</legend>
    <label>
      <input type="radio" name="transition" value="FadeIn" checked>Fade In
    </label><br/>
      <label class="options">
        Duration (in s):
        <input type="text" size="3" name="FadeInDuration" value="1">
      </label><br/>
    <label>
      <input type="radio" name="transition" value="FadeOut">Fade Out
    </label><br/>
      <label class="options">
        Duration (in s):
        <input type="text" size="3" name="FadeOutDuration" value="1">
      </label><br/>
    <label>
      <input type="radio" name="transition" value="Fade">Fade
    </label><br/>
      <label class="options">
        Duration (in s):
        <input type="text" size="3" name="FadeDuration" value=".5">
      </label><br/>
      <label class="options">
        CSS3 timing:
        <input type="text" size="7" name="FadeTimingFn" value="ease-in">
      </label><br/>
      <label class="options">
        Starting opacity:
        <input type="text" size="3" name="FadeStartingOpacity" value=".2">
      </label><br/>
      <label class="options">
        Ending opacity:
        <input type="text" size="3" name="FadeEndingOpacity" value=".8">
      </label>
    <div id="demo-buttons">
      <input type="button" id="animate-btn" value="Animate!"></input>
      <input type="button" id="reset-btn" value="Reset"></input>
    </div>
  </fieldset>
</form>
</div>
<div class="demo-panel">
  <div id="demo-animated-box">Hi there!</div>
</div>

<!-- Logging panel -->
<fieldset class="goog-debug-panel">
  <legend>Event log for the transition object</legend>
  <div id="log"></div>
</fieldset>

<script>
// Set up debug console.
var logger = goog.debug.Logger.getLogger('Demo');
new goog.debug.DivConsole(goog.dom.getElement('log')).
    setCapturing(true);
var eventTypes = goog.object.getValues(goog.fx.Transition.EventType);

var isPlaying = false;
var transition;
var animatedBox = goog.dom.getElement('demo-animated-box');
var animateButton = goog.dom.getElement('animate-btn');
var resetButton = goog.dom.getElement('reset-btn');

function fadeIn() {
  var duration = parseFloat(getValue_('FadeInDuration'));

  transition = goog.fx.css3.fadeIn(animatedBox, duration);
  installListener_(transition);
  transition.play();
}

function fadeOut() {
  var duration = parseFloat(getValue_('FadeOutDuration'));

  transition = goog.fx.css3.fadeOut(animatedBox, duration);
  installListener_(transition);
  transition.play();
}

function fade() {
  var duration = parseFloat(getValue_('FadeDuration'));
  var timingFn = getValue_('FadeTimingFn');
  var startOpacity = parseFloat(getValue_('FadeStartingOpacity'));
  var endOpacity = parseFloat(getValue_('FadeEndingOpacity'));

  transition = goog.fx.css3.fade(
      animatedBox, duration, timingFn, startOpacity, endOpacity);
  installListener_(transition);
  transition.play();
}

function animate() {
  stopOrReset();
  goog.dispose(transition);
  goog.Timer.callOnce(animate_);
}

function animate_() {
  isPlaying = true;
  resetButton.value = 'Stop';

  var transitionType = getValue_('transition');
  switch (transitionType) {
    case 'FadeIn': fadeIn(); break;
    case 'FadeOut': fadeOut(); break;
    case 'Fade': fade(); break;
  }

  goog.events.listen(
      transition, goog.fx.Transition.EventType.END, function() {
        isPlaying = false;
        resetButton.value = 'Reset';
      });
}

function stopOrReset() {
  if (!transition) return;

  if (isPlaying) {
    isPlaying = false;
    resetButton.value = 'Reset';
    transition.stop();
  } else {
    transition.dispose();
    // Resets all the possible overriding (for now just opacity due to fade).
    animatedBox.style.opacity = '';
  }
}

function getValue_(name) {
  var elements = document.forms[0].elements[name];
  if (goog.isArrayLike(elements)) {
    for (var i = 0; i < elements.length; ++i) {
      if (elements[i].checked) return elements[i].value;
    }
  }

  return elements.value;
}

function installListener_(transition) {
  goog.events.listen(transition, eventTypes, function(e) {
    logger.info('Fired event: ' + e.type);
  });
}

goog.events.listen(
    new goog.events.ActionHandler(animateButton),
    goog.events.ActionHandler.EventType.ACTION, animate);
goog.events.listen(
    new goog.events.ActionHandler(resetButton),
    goog.events.ActionHandler.EventType.ACTION, stopOrReset);

</script>
</body>
</html>