effects.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 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. <title>goog.fx.dom</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.events');
  13. goog.require('goog.fx');
  14. goog.require('goog.fx.dom');
  15. </script>
  16. <link rel="stylesheet" href="css/demo.css">
  17. <style>
  18. #test1 {
  19. position: absolute;
  20. left: 150px;
  21. top: 100px;
  22. width: 20px;
  23. height: 20px;
  24. background-color: rgb(0,0,0);
  25. }
  26. button {
  27. font: normal 10px arial;
  28. width: 125px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <h1>goog.fx.dom</h1>
  34. <p><strong>Demonstrations of the goog.fx.dom library</strong></p>
  35. <p>
  36. <button id="but0" onclick="slide(0, 0);">Slide To 0x0</button><br>
  37. <button id="but1" onclick="slide(400, 40);">Slide To 400x40</button><br>
  38. <button id="but2" onclick="slide(300, 200);">Slide To 300x200</button><br>
  39. <button id="but3" onclick="slide(600, 100);">Slide To 600x100</button>
  40. </p>
  41. <p>
  42. <button id="but4" onclick="resize(50, 50);">Resize To 50x50</button><br>
  43. <button id="but5" onclick="resize(250, 50);">Resize To 250x50</button><br>
  44. <button id="but6" onclick="resize(5, 5);">Resize To 5x5</button><br>
  45. <button id="but7" onclick="resize(250, 250);">Resize To 250x250</button><br>
  46. <button id="but8" onclick="resize(1250, 1250);">Resize To 1250x1250</button>
  47. </p>
  48. <p>
  49. <button id="but9" onclick="fadeout();">Fade Out</button><br>
  50. <button id="but10" onclick="fadein();">Fade In</button>
  51. </p>
  52. <p>
  53. <button id="but11" onclick="color(200, 0, 0);">Transform to red</button><br>
  54. <button id="but12" onclick="color(180, 180, 180);">Transform to grey</button><br>
  55. <button id="but13" onclick="color(0, 0, 0);">Transform to black</button><br>
  56. <button id="but14" onclick="color(100, 100, 255);">Transform to blue</button>
  57. </p>
  58. <p>
  59. <button id="but15" onclick="toggleRequestAnimationFrame();"></button>
  60. <p>
  61. <div id="test1"><!-- This comment is an IE6 hack to fix height:20px --></div>
  62. <script>
  63. var col = [0, 0, 0];
  64. var duration = 1000;
  65. var el = document.getElementById('test1');
  66. /**
  67. * Enables all buttons then disposes of the animation.
  68. * @param {!goog.events.Event} e goog.fx.Transition.EventType.END event with
  69. * the goog.fx.Animation object in its target.
  70. */
  71. function enableButtons(e) {
  72. for (var i = 0; i <= 15; i++) {
  73. document.getElementById('but' + i).disabled = false;
  74. }
  75. e.target.dispose();
  76. }
  77. function disableButtons() {
  78. for (var i = 0; i <= 15; i++) {
  79. document.getElementById('but' + i).disabled = true;
  80. }
  81. }
  82. function slide(a, b) {
  83. var x = el.offsetLeft;
  84. var y = el.offsetTop;
  85. var anim = new goog.fx.dom.Slide(el, [x, y], [a, b], duration,
  86. goog.fx.easing.easeOut);
  87. goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN,
  88. disableButtons);
  89. goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons);
  90. anim.play();
  91. }
  92. function resize(a, b) {
  93. var w = el.offsetWidth;
  94. var h = el.offsetHeight;
  95. var anim = new goog.fx.dom.Resize(el, [w, h], [a, b], duration,
  96. goog.fx.easing.easeOut);
  97. goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN,
  98. disableButtons);
  99. goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons);
  100. anim.play();
  101. }
  102. function fadeout() {
  103. var anim = new goog.fx.dom.FadeOutAndHide(el, duration);
  104. goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN,
  105. disableButtons);
  106. goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons);
  107. anim.play();
  108. }
  109. function fadein() {
  110. var anim = new goog.fx.dom.FadeInAndShow(el, duration);
  111. goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN,
  112. disableButtons);
  113. goog.events.listen(anim, goog.fx.Transition.EventType.END, enableButtons);
  114. anim.play();
  115. }
  116. function color(r, g, b) {
  117. var anim = new goog.fx.dom.BgColorTransform(el, col, [r, g, b], duration);
  118. goog.events.listen(anim, goog.fx.Transition.EventType.BEGIN,
  119. disableButtons);
  120. goog.events.listen(anim, goog.fx.Transition.EventType.END, function(e) {
  121. col = [e.x, e.y, e.z];
  122. enableButtons();
  123. });
  124. anim.play();
  125. }
  126. function toggleRequestAnimationFrame() {
  127. rafEnabled = !rafEnabled;
  128. goog.fx.Animation.setAnimationWindow(rafEnabled ? window : null);
  129. updateRafButton();
  130. }
  131. function updateRafButton() {
  132. goog.dom.setTextContent(goog.dom.getElement('but15'),
  133. rafEnabled ?
  134. 'Disable timing control API' : 'Enable timing control API');
  135. }
  136. goog.fx.Animation.setAnimationWindow(window);
  137. var rafEnabled = goog.fx.Animation.animationWindow_;
  138. updateRafButton();
  139. </script>
  140. </body>
  141. </html>