fx.js 5.0 KB

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