fx.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.css3.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.css3.fx"] = true;
  8. dojo.provide("dojox.css3.fx");
  9. dojo.require("dojo.fx");
  10. dojo.require("dojox.html.ext-dojo.style");
  11. dojo.require("dojox.fx.ext-dojo.complex");
  12. dojo.mixin(dojox.css3.fx, {
  13. puff: function(args){
  14. // summary:
  15. // Returns an animation that will do a "puff" effect on the given node
  16. //
  17. // description:
  18. // Fades out an element and scales it to args.endScale
  19. //
  20. return dojo.fx.combine([dojo.fadeOut(args),
  21. this.expand({
  22. node: args.node,
  23. endScale: args.endScale || 2
  24. })
  25. ]);
  26. },
  27. expand: function(args){
  28. // summary:
  29. // Returns an animation that expands args.node
  30. //
  31. // description:
  32. // Scales an element to args.endScale
  33. //
  34. return dojo.animateProperty({
  35. node: args.node,
  36. properties: {
  37. transform: { start: "scale(1)", end: "scale(" + [args.endScale || 3] + ")" }
  38. }
  39. });
  40. },
  41. shrink: function(args){
  42. // summary:
  43. // Returns an animation that shrinks args.node
  44. //
  45. // description:
  46. // Shrinks an element, same as expand({ node: node, endScale: .01 });
  47. //
  48. return this.expand({
  49. node: args.node,
  50. endScale: .01
  51. });
  52. },
  53. rotate: function(args){
  54. // summary:
  55. // Returns an animation that rotates an element
  56. //
  57. // description:
  58. // Rotates an element from args.startAngle to args.endAngle
  59. //
  60. return dojo.animateProperty({
  61. node: args.node,
  62. duration: args.duration || 1000,
  63. properties: {
  64. transform: { start: "rotate(" + (args.startAngle || "0deg") + ")", end: "rotate(" + (args.endAngle || "360deg") + ")" }
  65. }
  66. });
  67. },
  68. flip: function(args){
  69. // summary:
  70. // Returns an animation that flips an element around his y axis
  71. //
  72. // description:
  73. // Flips an element around his y axis. The default is a 360deg flip
  74. // but it's possible to run a partial flip using args.whichAnims
  75. //
  76. // example:
  77. // | // half flip
  78. // | dojox.css3.fx.flip({
  79. // | node: domNode,
  80. // | whichAnim: [0, 1]
  81. // | }).play();
  82. //
  83. var anims = [],
  84. whichAnims = args.whichAnims || [0, 1, 2, 3],
  85. direction = args.direction || 1,
  86. transforms = [
  87. { start: "scale(1, 1) skew(0deg,0deg)", end: "scale(0, 1) skew(0," + (direction * 30) + "deg)" },
  88. { start: "scale(0, 1) skew(0deg," + (direction * 30) + "deg)", end: "scale(-1, 1) skew(0deg,0deg)" },
  89. { start: "scale(-1, 1) skew(0deg,0deg)", end: "scale(0, 1) skew(0deg," + (-direction * 30) + "deg)" },
  90. { start: "scale(0, 1) skew(0deg," + (-direction * 30) + "deg)", end: "scale(1, 1) skew(0deg,0deg)" }
  91. ];
  92. for(var i = 0; i < whichAnims.length; i++){
  93. anims.push(dojo.animateProperty(
  94. dojo.mixin({
  95. node: args.node,
  96. duration: args.duration || 600,
  97. properties: {
  98. transform: transforms[whichAnims[i]]
  99. }}, args)
  100. ));
  101. }
  102. return dojo.fx.chain(anims);
  103. },
  104. bounce: function(args){
  105. // summary:
  106. // Returns an animation that do a "bounce" effect on args.node
  107. //
  108. // description:
  109. // Vertical bounce animation, the scaleX, scaleY deformation and the
  110. // jump height (args.jumpHeight) can be specified
  111. //
  112. var anims = [],
  113. n = args.node,
  114. duration = args.duration || 1000,
  115. scaleX = args.scaleX || 1.2,
  116. scaleY = args.scaleY || .6,
  117. ds = dojo.style,
  118. oldPos = ds(n, "position"),
  119. newPos = "absolute",
  120. oldTop = ds(n, "top"),
  121. combinedAnims = [],
  122. bTime = 0,
  123. round = Math.round,
  124. jumpHeight = args.jumpHeight || 70
  125. ;
  126. if(oldPos !== "absolute"){
  127. newPos = "relative";
  128. }
  129. var a1 = dojo.animateProperty({
  130. node: n,
  131. duration: duration / 6,
  132. properties: {
  133. transform: { start: "scale(1, 1)", end: "scale(" + scaleX + ", " + scaleY + ")" }
  134. }
  135. });
  136. dojo.connect(a1, "onBegin", function(){
  137. ds(n, {
  138. transformOrigin: "50% 100%",
  139. position: newPos
  140. });
  141. });
  142. anims.push(a1);
  143. var a2 = dojo.animateProperty({
  144. node: n,
  145. duration: duration / 6,
  146. properties: {
  147. transform: { end: "scale(1, 1)", start: "scale(" + scaleX + ", " + scaleY + ")" }
  148. }
  149. });
  150. combinedAnims.push(a2);
  151. combinedAnims.push(new dojo.Animation(dojo.mixin({
  152. curve: [],
  153. duration: duration / 3,
  154. delay: duration / 12,
  155. onBegin: function(){
  156. bTime = (new Date).getTime();
  157. },
  158. onAnimate: function(){
  159. var cTime = (new Date).getTime();
  160. ds(n, {
  161. top: parseInt(ds(n, "top")) - round(jumpHeight*((cTime-bTime)/this.duration)) + "px"
  162. });
  163. bTime = cTime;
  164. }
  165. }, args)));
  166. anims.push(dojo.fx.combine(combinedAnims));
  167. anims.push(dojo.animateProperty(dojo.mixin({
  168. duration: duration / 3,
  169. onEnd: function(){
  170. ds(n, {
  171. position: oldPos
  172. });
  173. },
  174. properties:{
  175. top: oldTop
  176. }
  177. }, args)));
  178. anims.push(a1);
  179. anims.push(a2);
  180. return dojo.fx.chain(anims);
  181. }
  182. });
  183. }