aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/animationqueue.html
blob: 451836abbd027faec68f664fd2b5c606f6c0f210 (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
<!DOCTYPE html>
<html>
<!--
Copyright 2007 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.
-->
  <head>
    <script src="../base.js"></script>

    <script>
      goog.require('goog.dom');
      goog.require('goog.fx');
      goog.require('goog.fx.dom');
      goog.require('goog.fx.AnimationQueue');
    </script>
    <script>
      var sx = 5;
      var sy = 5;

      var isForward = false;

      var parallelForward;
      var parallelBackward;
      var serialForward;
      var serialBackward;
      var currentlyPlaying;

      function createAnimations() {
        parallelForward = new goog.fx.AnimationParallelQueue();
        parallelBackward = new goog.fx.AnimationParallelQueue();
        serialForward = new goog.fx.AnimationSerialQueue();
        serialBackward = new goog.fx.AnimationSerialQueue();

        // move forward at the same time
        parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
            [5, 5], [55, 50], 2000, goog.fx.easing.easeOut));
        parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
            [10, 5], [60, 50], 2000, goog.fx.easing.easeOut));
        parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
            [15, 5], [65, 50], 2000, goog.fx.easing.easeOut));
        parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
            [20, 5], [70, 50], 2000, goog.fx.easing.easeOut));
        parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
            [25, 5], [75, 50], 2000, goog.fx.easing.easeOut));

        // move backward at the same time
        parallelBackward.add(new goog.fx.dom.Slide(
            goog.dom.getElement("block1"),
            [55, 50], [5, 5], 2000, goog.fx.easing.easeOut));
        parallelBackward.add(new goog.fx.dom.Slide(
            goog.dom.getElement("block2"),
            [60, 50], [10, 5], 2000, goog.fx.easing.easeOut));
        parallelBackward.add(new goog.fx.dom.Slide
            (goog.dom.getElement("block3"),
            [65, 50], [15, 5], 2000, goog.fx.easing.easeOut));
        parallelBackward.add(new goog.fx.dom.Slide(
            goog.dom.getElement("block4"),
            [70, 50], [20, 5], 2000, goog.fx.easing.easeOut));
        parallelBackward.add(new goog.fx.dom.Slide(
            goog.dom.getElement("block5"),
            [75, 50], [25, 5], 2000, goog.fx.easing.easeOut));

        // move forward in order
        serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
            [5, 5], [55, 50], 400, goog.fx.easing.easeOut));
        serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
            [10, 5], [60, 50], 400, goog.fx.easing.easeOut));
        serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
            [15, 5], [65, 50], 400, goog.fx.easing.easeOut));
        serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
            [20, 5], [70, 50], 400, goog.fx.easing.easeOut));
        serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
            [25, 5], [75, 50], 400, goog.fx.easing.easeOut));

        // move backward in order
        serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
            [55, 50], [5, 5], 400, goog.fx.easing.easeOut));
        serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
            [60, 50], [10, 5], 400, goog.fx.easing.easeOut));
        serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
            [65, 50], [15, 5], 400, goog.fx.easing.easeOut));
        serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
            [70, 50], [20, 5], 400, goog.fx.easing.easeOut));
        serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
            [75, 50], [25, 5], 400, goog.fx.easing.easeOut));
      }

      function demoParallel() {
        if (isForward) {
          parallelBackward.play();
          currentlyPlaying = parallelBackward;
        } else {
          parallelForward.play();
          currentlyPlaying = parallelForward;
        }
        isForward = !isForward;
      }

      function demoSerial() {
        if (isForward) {
          serialBackward.play();
          currentlyPlaying = serialBackward;
        } else {
          serialForward.play();
          currentlyPlaying = serialForward;
        }
        isForward = !isForward;
      }

      function pause() {
        currentlyPlaying.pause();
      }

      function resume(doRestart) {
        currentlyPlaying.play(doRestart);
      }
    </script>

    <style>
      .block {
        position: absolute;
        width: 5px;
        height: 5px;
        background-color: blue;
      }
    </style>
  </head>
  <body>
    <div id="block1" class="block" style="left:  5px; top: 5px"></div>
    <div id="block2" class="block" style="left: 10px; top: 5px"></div>
    <div id="block3" class="block" style="left: 15px; top: 5px"></div>
    <div id="block4" class="block" style="left: 20px; top: 5px"></div>
    <div id="block5" class="block" style="left: 25px; top: 5px"></div>

    <script>
      createAnimations();
    </script>

    <div style="margin-top:70px">
      <a href="javascript:demoParallel();">play parallel</a> |
      <a href="javascript:demoSerial();">play serial</a> | <br/>
      <a href="javascript:pause();">pause</a> |
      <a href="javascript:resume(false);">resume</a> |
      <a href="javascript:resume(true);">resume + restart</a>
    </div>
  </body>
</html>