source: Dev/trunk/src/client/dojox/css3/fx.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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