MCPcopy Index your code
hub / github.com/jquery/jquery / adjustCSS

Function adjustCSS

dist-module/jquery.module.js:4127–4190  ·  view source on GitHub ↗
( elem, prop, valueParts, tween )

Source from the content-addressed store, hash-verified

4125}
4126
4127function adjustCSS( elem, prop, valueParts, tween ) {
4128 var adjusted, scale,
4129 maxIterations = 20,
4130 currentValue = tween ?
4131 function() {
4132 return tween.cur();
4133 } :
4134 function() {
4135 return jQuery.css( elem, prop, "" );
4136 },
4137 initial = currentValue(),
4138 unit = valueParts && valueParts[ 3 ] || ( isAutoPx( prop ) ? "px" : "" ),
4139
4140 // Starting value computation is required for potential unit mismatches
4141 initialInUnit = elem.nodeType &&
4142 ( !isAutoPx( prop ) || unit !== "px" && +initial ) &&
4143 rcssNum.exec( jQuery.css( elem, prop ) );
4144
4145 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
4146
4147 // Support: Firefox <=54 - 66+
4148 // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
4149 initial = initial / 2;
4150
4151 // Trust units reported by jQuery.css
4152 unit = unit || initialInUnit[ 3 ];
4153
4154 // Iteratively approximate from a nonzero starting point
4155 initialInUnit = +initial || 1;
4156
4157 while ( maxIterations-- ) {
4158
4159 // Evaluate and update our best guess (doubling guesses that zero out).
4160 // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
4161 jQuery.style( elem, prop, initialInUnit + unit );
4162 if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {
4163 maxIterations = 0;
4164 }
4165 initialInUnit = initialInUnit / scale;
4166
4167 }
4168
4169 initialInUnit = initialInUnit * 2;
4170 jQuery.style( elem, prop, initialInUnit + unit );
4171
4172 // Make sure we update the tween properties later on
4173 valueParts = valueParts || [];
4174 }
4175
4176 if ( valueParts ) {
4177 initialInUnit = +initialInUnit || +initial || 0;
4178
4179 // Apply relative offset (+=/-=) if specified
4180 adjusted = valueParts[ 1 ] ?
4181 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
4182 +valueParts[ 2 ];
4183 if ( tween ) {
4184 tween.unit = unit;

Callers 1

jQueryFactoryFunction · 0.70

Calls 2

currentValueFunction · 0.70
isAutoPxFunction · 0.70

Tested by

no test coverage detected