cssspriteanimation.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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>CssSpriteAnimation demo</title>
  10. <script type="text/javascript" src="../base.js"></script>
  11. <script type="text/javascript">
  12. goog.require('goog.events');
  13. goog.require('goog.fx.Animation');
  14. goog.require('goog.fx.CssSpriteAnimation');
  15. goog.require('goog.math.Box');
  16. goog.require('goog.math.Size');
  17. </script>
  18. <style>
  19. .icon {
  20. width: 11px;
  21. height: 11px;
  22. background-image: url(../images/offlineicons.png);
  23. }
  24. #test1,
  25. #test3 {
  26. background-position: 0 -11px;
  27. }
  28. #test2 {
  29. background-position: 0 -132px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <p>The following just runs and runs...</p>
  35. <div class=icon id=test1></div>
  36. <p>The animation is just an ordinary animation so you can pause it etc.
  37. <div class=icon id=test2></div>
  38. <p>
  39. <button onclick="sa2.play()">Play</button>
  40. <button onclick="sa2.pause()">Pause</button>
  41. </p>
  42. <p>The animation can be played once by stopping it after it finishes for the
  43. first time.
  44. <div class=icon id=test3></div>
  45. <script>
  46. var size = new goog.math.Size(11, 11);
  47. var el = document.getElementById('test1');
  48. var sa = new goog.fx.CssSpriteAnimation(el, size,
  49. new goog.math.Box(11, 11, 99, 0), 1200);
  50. sa.play();
  51. var el2 = document.getElementById('test2');
  52. var sa2 = new goog.fx.CssSpriteAnimation(el2, size,
  53. new goog.math.Box(132, 11, 132 + 11 * 8, 0), 1200);
  54. sa2.play();
  55. var el3 = document.getElementById('test3');
  56. var sa3 = new goog.fx.CssSpriteAnimation(el3, size,
  57. new goog.math.Box(11, 11, 99, 0), 8000);
  58. goog.events.listen(sa3, goog.fx.Transition.EventType.FINISH, function() {
  59. sa3.stop();
  60. });
  61. sa3.play();
  62. </script>
  63. </body>
  64. </html>