animationqueue.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2007 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <script src="../base.js"></script>
  10. <script>
  11. goog.require('goog.dom');
  12. goog.require('goog.fx');
  13. goog.require('goog.fx.dom');
  14. goog.require('goog.fx.AnimationQueue');
  15. </script>
  16. <script>
  17. var sx = 5;
  18. var sy = 5;
  19. var isForward = false;
  20. var parallelForward;
  21. var parallelBackward;
  22. var serialForward;
  23. var serialBackward;
  24. var currentlyPlaying;
  25. function createAnimations() {
  26. parallelForward = new goog.fx.AnimationParallelQueue();
  27. parallelBackward = new goog.fx.AnimationParallelQueue();
  28. serialForward = new goog.fx.AnimationSerialQueue();
  29. serialBackward = new goog.fx.AnimationSerialQueue();
  30. // move forward at the same time
  31. parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
  32. [5, 5], [55, 50], 2000, goog.fx.easing.easeOut));
  33. parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
  34. [10, 5], [60, 50], 2000, goog.fx.easing.easeOut));
  35. parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
  36. [15, 5], [65, 50], 2000, goog.fx.easing.easeOut));
  37. parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
  38. [20, 5], [70, 50], 2000, goog.fx.easing.easeOut));
  39. parallelForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
  40. [25, 5], [75, 50], 2000, goog.fx.easing.easeOut));
  41. // move backward at the same time
  42. parallelBackward.add(new goog.fx.dom.Slide(
  43. goog.dom.getElement("block1"),
  44. [55, 50], [5, 5], 2000, goog.fx.easing.easeOut));
  45. parallelBackward.add(new goog.fx.dom.Slide(
  46. goog.dom.getElement("block2"),
  47. [60, 50], [10, 5], 2000, goog.fx.easing.easeOut));
  48. parallelBackward.add(new goog.fx.dom.Slide
  49. (goog.dom.getElement("block3"),
  50. [65, 50], [15, 5], 2000, goog.fx.easing.easeOut));
  51. parallelBackward.add(new goog.fx.dom.Slide(
  52. goog.dom.getElement("block4"),
  53. [70, 50], [20, 5], 2000, goog.fx.easing.easeOut));
  54. parallelBackward.add(new goog.fx.dom.Slide(
  55. goog.dom.getElement("block5"),
  56. [75, 50], [25, 5], 2000, goog.fx.easing.easeOut));
  57. // move forward in order
  58. serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
  59. [5, 5], [55, 50], 400, goog.fx.easing.easeOut));
  60. serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
  61. [10, 5], [60, 50], 400, goog.fx.easing.easeOut));
  62. serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
  63. [15, 5], [65, 50], 400, goog.fx.easing.easeOut));
  64. serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
  65. [20, 5], [70, 50], 400, goog.fx.easing.easeOut));
  66. serialForward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
  67. [25, 5], [75, 50], 400, goog.fx.easing.easeOut));
  68. // move backward in order
  69. serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block1"),
  70. [55, 50], [5, 5], 400, goog.fx.easing.easeOut));
  71. serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block2"),
  72. [60, 50], [10, 5], 400, goog.fx.easing.easeOut));
  73. serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block3"),
  74. [65, 50], [15, 5], 400, goog.fx.easing.easeOut));
  75. serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block4"),
  76. [70, 50], [20, 5], 400, goog.fx.easing.easeOut));
  77. serialBackward.add(new goog.fx.dom.Slide(goog.dom.getElement("block5"),
  78. [75, 50], [25, 5], 400, goog.fx.easing.easeOut));
  79. }
  80. function demoParallel() {
  81. if (isForward) {
  82. parallelBackward.play();
  83. currentlyPlaying = parallelBackward;
  84. } else {
  85. parallelForward.play();
  86. currentlyPlaying = parallelForward;
  87. }
  88. isForward = !isForward;
  89. }
  90. function demoSerial() {
  91. if (isForward) {
  92. serialBackward.play();
  93. currentlyPlaying = serialBackward;
  94. } else {
  95. serialForward.play();
  96. currentlyPlaying = serialForward;
  97. }
  98. isForward = !isForward;
  99. }
  100. function pause() {
  101. currentlyPlaying.pause();
  102. }
  103. function resume(doRestart) {
  104. currentlyPlaying.play(doRestart);
  105. }
  106. </script>
  107. <style>
  108. .block {
  109. position: absolute;
  110. width: 5px;
  111. height: 5px;
  112. background-color: blue;
  113. }
  114. </style>
  115. </head>
  116. <body>
  117. <div id="block1" class="block" style="left: 5px; top: 5px"></div>
  118. <div id="block2" class="block" style="left: 10px; top: 5px"></div>
  119. <div id="block3" class="block" style="left: 15px; top: 5px"></div>
  120. <div id="block4" class="block" style="left: 20px; top: 5px"></div>
  121. <div id="block5" class="block" style="left: 25px; top: 5px"></div>
  122. <script>
  123. createAnimations();
  124. </script>
  125. <div style="margin-top:70px">
  126. <a href="javascript:demoParallel();">play parallel</a> |
  127. <a href="javascript:demoSerial();">play serial</a> | <br/>
  128. <a href="javascript:pause();">pause</a> |
  129. <a href="javascript:resume(false);">resume</a> |
  130. <a href="javascript:resume(true);">resume + restart</a>
  131. </div>
  132. </body>
  133. </html>