1
|
define( [
|
2
|
"../core",
|
3
|
"../css"
|
4
|
], function( jQuery ) {
|
5
|
|
6
|
"use strict";
|
7
|
|
8
|
function Tween( elem, options, prop, end, easing ) {
|
9
|
return new Tween.prototype.init( elem, options, prop, end, easing );
|
10
|
}
|
11
|
jQuery.Tween = Tween;
|
12
|
|
13
|
Tween.prototype = {
|
14
|
constructor: Tween,
|
15
|
init: function( elem, options, prop, end, easing, unit ) {
|
16
|
this.elem = elem;
|
17
|
this.prop = prop;
|
18
|
this.easing = easing || jQuery.easing._default;
|
19
|
this.options = options;
|
20
|
this.start = this.now = this.cur();
|
21
|
this.end = end;
|
22
|
this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
|
23
|
},
|
24
|
cur: function() {
|
25
|
var hooks = Tween.propHooks[ this.prop ];
|
26
|
|
27
|
return hooks && hooks.get ?
|
28
|
hooks.get( this ) :
|
29
|
Tween.propHooks._default.get( this );
|
30
|
},
|
31
|
run: function( percent ) {
|
32
|
var eased,
|
33
|
hooks = Tween.propHooks[ this.prop ];
|
34
|
|
35
|
if ( this.options.duration ) {
|
36
|
this.pos = eased = jQuery.easing[ this.easing ](
|
37
|
percent, this.options.duration * percent, 0, 1, this.options.duration
|
38
|
);
|
39
|
} else {
|
40
|
this.pos = eased = percent;
|
41
|
}
|
42
|
this.now = ( this.end - this.start ) * eased + this.start;
|
43
|
|
44
|
if ( this.options.step ) {
|
45
|
this.options.step.call( this.elem, this.now, this );
|
46
|
}
|
47
|
|
48
|
if ( hooks && hooks.set ) {
|
49
|
hooks.set( this );
|
50
|
} else {
|
51
|
Tween.propHooks._default.set( this );
|
52
|
}
|
53
|
return this;
|
54
|
}
|
55
|
};
|
56
|
|
57
|
Tween.prototype.init.prototype = Tween.prototype;
|
58
|
|
59
|
Tween.propHooks = {
|
60
|
_default: {
|
61
|
get: function( tween ) {
|
62
|
var result;
|
63
|
|
64
|
// Use a property on the element directly when it is not a DOM element,
|
65
|
// or when there is no matching style property that exists.
|
66
|
if ( tween.elem.nodeType !== 1 ||
|
67
|
tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {
|
68
|
return tween.elem[ tween.prop ];
|
69
|
}
|
70
|
|
71
|
// Passing an empty string as a 3rd parameter to .css will automatically
|
72
|
// attempt a parseFloat and fallback to a string if the parse fails.
|
73
|
// Simple values such as "10px" are parsed to Float;
|
74
|
// complex values such as "rotate(1rad)" are returned as-is.
|
75
|
result = jQuery.css( tween.elem, tween.prop, "" );
|
76
|
|
77
|
// Empty strings, null, undefined and "auto" are converted to 0.
|
78
|
return !result || result === "auto" ? 0 : result;
|
79
|
},
|
80
|
set: function( tween ) {
|
81
|
|
82
|
// Use step hook for back compat.
|
83
|
// Use cssHook if its there.
|
84
|
// Use .style if available and use plain properties where available.
|
85
|
if ( jQuery.fx.step[ tween.prop ] ) {
|
86
|
jQuery.fx.step[ tween.prop ]( tween );
|
87
|
} else if ( tween.elem.nodeType === 1 &&
|
88
|
( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null ||
|
89
|
jQuery.cssHooks[ tween.prop ] ) ) {
|
90
|
jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
|
91
|
} else {
|
92
|
tween.elem[ tween.prop ] = tween.now;
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
};
|
97
|
|
98
|
// Support: IE <=9 only
|
99
|
// Panic based approach to setting things on disconnected nodes
|
100
|
Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
|
101
|
set: function( tween ) {
|
102
|
if ( tween.elem.nodeType && tween.elem.parentNode ) {
|
103
|
tween.elem[ tween.prop ] = tween.now;
|
104
|
}
|
105
|
}
|
106
|
};
|
107
|
|
108
|
jQuery.easing = {
|
109
|
linear: function( p ) {
|
110
|
return p;
|
111
|
},
|
112
|
swing: function( p ) {
|
113
|
return 0.5 - Math.cos( p * Math.PI ) / 2;
|
114
|
},
|
115
|
_default: "swing"
|
116
|
};
|
117
|
|
118
|
jQuery.fx = Tween.prototype.init;
|
119
|
|
120
|
// Back compat <1.8 extension point
|
121
|
jQuery.fx.step = {};
|
122
|
|
123
|
} );
|