CSS: Support relative adjustment in any applicable unit

Fixes gh-1711
Closes gh-2011

(cherry picked from commit 9b03f6df88)

Conflicts:
	src/css.js
	src/effects.js
This commit is contained in:
Mr21
2015-02-04 14:10:14 +01:00
committed by Richard Gibson
parent 9edd95ffd7
commit 6fb2cefc60
5 changed files with 135 additions and 61 deletions

57
src/effects.js vendored
View File

@@ -1,8 +1,9 @@
define([
"./core",
"./var/pnum",
"./var/rcssNum",
"./css/var/cssExpand",
"./css/var/isHidden",
"./css/adjustCSS",
"./css/defaultDisplay",
"./core/init",
@@ -11,65 +12,17 @@ define([
"./css",
"./deferred",
"./traversing"
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay ) {
], function( jQuery, rcssNum, cssExpand, isHidden, adjustCSS, defaultDisplay ) {
var
fxNow, timerId,
rfxtypes = /^(?:toggle|show|hide)$/,
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
rrun = /queueHooks$/,
animationPrefilters = [ defaultPrefilter ],
tweeners = {
"*": [ function( prop, value ) {
var tween = this.createTween( prop, value ),
target = tween.cur(),
parts = rfxnum.exec( value ),
unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
// Starting value computation is required for potential unit mismatches
start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
rfxnum.exec( jQuery.css( tween.elem, prop ) ),
scale = 1,
maxIterations = 20;
if ( start && start[ 3 ] !== unit ) {
// Trust units reported by jQuery.css
unit = unit || start[ 3 ];
// Make sure we update the tween properties later on
parts = parts || [];
// Iteratively approximate from a nonzero starting point
start = +target || 1;
do {
// If previous iteration zeroed out, double until we get *something*
// Use a string for doubling factor so we don't accidentally see scale
// as unchanged below
scale = scale || ".5";
// Adjust and apply
start = start / scale;
jQuery.style( tween.elem, prop, start + unit );
// Update scale, tolerating zero or NaN from tween.cur()
// And breaking the loop if scale is unchanged or perfect,
// or if we've just had enough
} while (
scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations
);
}
// Update tween properties
if ( parts ) {
start = tween.start = +start || +target || 0;
tween.unit = unit;
// If a +=/-= token was provided, we're doing a relative animation
tween.end = parts[ 1 ] ?
start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
+parts[ 2 ];
}
var tween = this.createTween( prop, value );
adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
return tween;
} ]
};