MCPcopy Create free account
hub / github.com/OpenIntroStat/ims / adjustCSS

Function adjustCSS

libs/jquery-3.5.1/jquery-3.5.1.js:4738–4801  ·  view source on GitHub ↗
( elem, prop, valueParts, tween )

Source from the content-addressed store, hash-verified

4736
4737
4738function adjustCSS( elem, prop, valueParts, tween ) {
4739 var adjusted, scale,
4740 maxIterations = 20,
4741 currentValue = tween ?
4742 function() {
4743 return tween.cur();
4744 } :
4745 function() {
4746 return jQuery.css( elem, prop, "" );
4747 },
4748 initial = currentValue(),
4749 unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
4750
4751 // Starting value computation is required for potential unit mismatches
4752 initialInUnit = elem.nodeType &&
4753 ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
4754 rcssNum.exec( jQuery.css( elem, prop ) );
4755
4756 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
4757
4758 // Support: Firefox <=54
4759 // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
4760 initial = initial / 2;
4761
4762 // Trust units reported by jQuery.css
4763 unit = unit || initialInUnit[ 3 ];
4764
4765 // Iteratively approximate from a nonzero starting point
4766 initialInUnit = +initial || 1;
4767
4768 while ( maxIterations-- ) {
4769
4770 // Evaluate and update our best guess (doubling guesses that zero out).
4771 // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
4772 jQuery.style( elem, prop, initialInUnit + unit );
4773 if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {
4774 maxIterations = 0;
4775 }
4776 initialInUnit = initialInUnit / scale;
4777
4778 }
4779
4780 initialInUnit = initialInUnit * 2;
4781 jQuery.style( elem, prop, initialInUnit + unit );
4782
4783 // Make sure we update the tween properties later on
4784 valueParts = valueParts || [];
4785 }
4786
4787 if ( valueParts ) {
4788 initialInUnit = +initialInUnit || +initial || 0;
4789
4790 // Apply relative offset (+=/-=) if specified
4791 adjusted = valueParts[ 1 ] ?
4792 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
4793 +valueParts[ 2 ];
4794 if ( tween ) {
4795 tween.unit = unit;

Callers 1

jquery-3.5.1.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected