2 * L.Transition fallback implementation that powers Leaflet animation
3 * in browsers that don't support CSS3 Transitions
6 L
.Transition
= L
.Transition
.NATIVE
? L
.Transition
: L
.Transition
.extend({
8 getTime
: Date
.now
|| function() { return +new Date(); },
13 'ease': [0.25, 0.1, 0.25, 1.0],
14 'linear': [0.0, 0.0, 1.0, 1.0],
15 'ease-in': [0.42, 0, 1.0, 1.0],
16 'ease-out': [0, 0, 0.58, 1.0],
17 'ease-in-out': [0.42, 0, 0.58, 1.0]
20 CUSTOM_PROPS_GETTERS
: {
21 position
: L
.DomUtil
.getPosition
24 //used to get units from strings like "10.5px" (->px)
25 UNIT_RE
: /^[\d\.]+(\D*)$/
32 initialize: function(el
, options
) {
34 L
.Util
.extend(this.options
, options
);
36 var easings
= L
.Transition
.EASINGS
[this.options
.easing
] || L
.Transition
.EASINGS
['ease'];
38 this._p1
= new L
.Point(0, 0);
39 this._p2
= new L
.Point(easings
[0], easings
[1]);
40 this._p3
= new L
.Point(easings
[2], easings
[3]);
41 this._p4
= new L
.Point(1, 1);
43 this._step
= L
.Util
.bind(this._step
, this);
44 this._interval
= Math
.round(1000 / this.options
.fps
);
47 run: function(props
) {
50 var getters
= L
.Transition
.CUSTOM_PROPS_GETTERS
,
51 re
= L
.Transition
.UNIT_RE
;
55 for (var prop
in props
) {
56 if (props
.hasOwnProperty(prop
)) {
58 if (prop
in getters
) {
59 p
.from = getters
[prop
](this._el
);
61 var matches
= this._el
.style
[prop
].match(re
);
62 p
.from = parseFloat(matches
[0]);
66 this._props
[prop
] = p
;
70 clearInterval(this._timer
);
71 this._timer
= setInterval(this._step
, this._interval
);
72 this._startTime
= L
.Transition
.getTime();
76 var time
= L
.Transition
.getTime(),
77 elapsed
= time
- this._startTime
,
78 duration
= this.options
.duration
* 1000;
80 if (elapsed
< duration
) {
81 this._runFrame(this._cubicBezier(elapsed
/ duration
));
88 _runFrame: function(percentComplete
) {
89 var setters
= L
.Transition
.CUSTOM_PROPS_SETTERS
,
92 for (prop
in this._props
) {
93 if (this._props
.hasOwnProperty(prop
)) {
94 p
= this._props
[prop
];
95 if (prop
in setters
) {
96 value
= p
.to
.subtract(p
.from).multiplyBy(percentComplete
).add(p
.from);
97 setters
[prop
](this._el
, value
);
99 this._el
.style
[prop
] =
100 ((p
.to
- p
.from) * percentComplete
+ p
.from) + p
.unit
;
107 _complete: function() {
108 clearInterval(this._timer
);
112 _cubicBezier: function(t
) {
113 var a
= Math
.pow(1 - t
, 3),
114 b
= 3 * Math
.pow(1 - t
, 2) * t
,
115 c
= 3 * (1 - t
) * Math
.pow(t
, 2),
117 p1
= this._p1
.multiplyBy(a
),
118 p2
= this._p2
.multiplyBy(b
),
119 p3
= this._p3
.multiplyBy(c
),
120 p4
= this._p4
.multiplyBy(d
);
122 return p1
.add(p2
).add(p3
).add(p4
).y
;