Skip to content

Commit

Permalink
.css(), the values like +=10% aren't ignored anymore (like .animate())
Browse files Browse the repository at this point in the history
  • Loading branch information
mr21 committed Jan 13, 2015
1 parent 74ae544 commit 92ebc46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
15 changes: 12 additions & 3 deletions src/css.js
Expand Up @@ -26,7 +26,7 @@ var
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
rrelNum = new RegExp( "^([+-])=(" + pnum + ")(.*)", "i" ),

cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssNormalTransform = {
Expand Down Expand Up @@ -248,6 +248,15 @@ jQuery.extend({
"float": "cssFloat"
},

cssCastUnity: function( elem, prop, unit ) {
var vA = jQuery.css( elem, prop, "" );
if ( unit !== "px" ) {
jQuery.style( elem, prop, vA + unit );
return vA / jQuery.css( elem, prop, "" ) * vA;
}
return vA;
},

// Get and set the style property on a DOM Node
style: function( elem, name, value, extra ) {

Expand All @@ -273,7 +282,7 @@ jQuery.extend({

// Convert "+=" or "-=" to relative numbers (#7345)
if ( type === "string" && (ret = rrelNum.exec( value )) ) {
value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
value = ( ret[1] + 1 ) * ret[2] + jQuery.cssCastUnity( elem, name, ret[3] );
// Fixes bug #9237
type = "number";
}
Expand All @@ -285,7 +294,7 @@ jQuery.extend({

// If a number was passed in, add 'px' (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";
value += ret && ret[3] ? ret[3] : "px";
}

// Support: IE9-11+
Expand Down
28 changes: 2 additions & 26 deletions src/effects.js
Expand Up @@ -30,34 +30,10 @@ var

// 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;
rfxnum.exec( jQuery.css( tween.elem, prop ) );

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 string for doubling 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(),
// break the loop if scale is unchanged or perfect, or if we've just had enough
} while (
scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations
);
start = jQuery.cssCastUnity( tween.elem, prop, unit );
}

// Update tween properties
Expand Down

0 comments on commit 92ebc46

Please sign in to comment.