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

Function adjustCSS

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

Source from the content-addressed store, hash-verified

5522}
5523
5524function adjustCSS( elem, prop, valueParts, tween ) {
5525 var adjusted, scale,
5526 maxIterations = 20,
5527 currentValue = function() {
5528 return jQuery.css( elem, prop, "" );
5529 },
5530 initial = currentValue(),
5531 unit = valueParts && valueParts[ 3 ] || ( isAutoPx( prop ) ? "px" : "" ),
5532
5533 // Starting value computation is required for potential unit mismatches
5534 initialInUnit = elem.nodeType &&
5535 ( !isAutoPx( prop ) || unit !== "px" && +initial ) &&
5536 rcssNum.exec( jQuery.css( elem, prop ) );
5537
5538 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
5539
5540 // Support: Firefox <=54 - 66+
5541 // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
5542 initial = initial / 2;
5543
5544 // Trust units reported by jQuery.css
5545 unit = unit || initialInUnit[ 3 ];
5546
5547 // Iteratively approximate from a nonzero starting point
5548 initialInUnit = +initial || 1;
5549
5550 while ( maxIterations-- ) {
5551
5552 // Evaluate and update our best guess (doubling guesses that zero out).
5553 // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
5554 jQuery.style( elem, prop, initialInUnit + unit );
5555 if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {
5556 maxIterations = 0;
5557 }
5558 initialInUnit = initialInUnit / scale;
5559
5560 }
5561
5562 initialInUnit = initialInUnit * 2;
5563 jQuery.style( elem, prop, initialInUnit + unit );
5564
5565 // Make sure we update the tween properties later on
5566 valueParts = valueParts || [];
5567 }
5568
5569 if ( valueParts ) {
5570 initialInUnit = +initialInUnit || +initial || 0;
5571
5572 // Apply relative offset (+=/-=) if specified
5573 adjusted = valueParts[ 1 ] ?
5574 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
5575 +valueParts[ 2 ];
5576 }
5577 return adjusted;
5578}
5579
5580var cssPrefixes = [ "Webkit", "Moz", "ms" ],
5581 emptyStyle = document$1.createElement( "div" ).style;

Callers 1

jQueryFactoryFunction · 0.70

Calls 2

currentValueFunction · 0.70
isAutoPxFunction · 0.70

Tested by

no test coverage detected