1 import { jQuery } from "../core.js";
2 import { isAutoPx } from "../css/isAutoPx.js";
3 import { finalPropName } from "../css/finalPropName.js";
7 function Tween( elem, options, prop, end, easing ) {
8 return new Tween.prototype.init( elem, options, prop, end, easing );
14 init: function( elem, options, prop, end, easing, unit ) {
17 this.easing = easing || jQuery.easing._default;
18 this.options = options;
19 this.start = this.now = this.cur();
21 this.unit = unit || ( isAutoPx( prop ) ? "px" : "" );
24 var hooks = Tween.propHooks[ this.prop ];
26 return hooks && hooks.get ?
28 Tween.propHooks._default.get( this );
30 run: function( percent ) {
32 hooks = Tween.propHooks[ this.prop ];
34 if ( this.options.duration ) {
35 this.pos = eased = jQuery.easing[ this.easing ](
36 percent, this.options.duration * percent, 0, 1, this.options.duration
39 this.pos = eased = percent;
41 this.now = ( this.end - this.start ) * eased + this.start;
43 if ( this.options.step ) {
44 this.options.step.call( this.elem, this.now, this );
47 if ( hooks && hooks.set ) {
50 Tween.propHooks._default.set( this );
56 Tween.prototype.init.prototype = Tween.prototype;
60 get: function( tween ) {
63 // Use a property on the element directly when it is not a DOM element,
64 // or when there is no matching style property that exists.
65 if ( tween.elem.nodeType !== 1 ||
66 tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {
67 return tween.elem[ tween.prop ];
70 // Passing an empty string as a 3rd parameter to .css will automatically
71 // attempt a parseFloat and fallback to a string if the parse fails.
72 // Simple values such as "10px" are parsed to Float;
73 // complex values such as "rotate(1rad)" are returned as-is.
74 result = jQuery.css( tween.elem, tween.prop, "" );
76 // Empty strings, null, undefined and "auto" are converted to 0.
77 return !result || result === "auto" ? 0 : result;
79 set: function( tween ) {
81 // Use step hook for back compat.
82 // Use cssHook if its there.
83 // Use .style if available and use plain properties where available.
84 if ( jQuery.fx.step[ tween.prop ] ) {
85 jQuery.fx.step[ tween.prop ]( tween );
86 } else if ( tween.elem.nodeType === 1 && (
87 jQuery.cssHooks[ tween.prop ] ||
88 tween.elem.style[ finalPropName( tween.prop ) ] != null ) ) {
89 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
91 tween.elem[ tween.prop ] = tween.now;
98 linear: function( p ) {
101 swing: function( p ) {
102 return 0.5 - Math.cos( p * Math.PI ) / 2;
107 jQuery.fx = Tween.prototype.init;
109 // Back compat <1.8 extension point