MCPcopy
hub / github.com/jquery/jquery / adjustCSS

Function adjustCSS

src/css/adjustCSS.js:5–68  ·  view source on GitHub ↗
( elem, prop, valueParts, tween )

Source from the content-addressed store, hash-verified

3import { rcssNum } from "../var/rcssNum.js";
4
5export function adjustCSS( elem, prop, valueParts, tween ) {
6 var adjusted, scale,
7 maxIterations = 20,
8 currentValue = tween ?
9 function() {
10 return tween.cur();
11 } :
12 function() {
13 return jQuery.css( elem, prop, "" );
14 },
15 initial = currentValue(),
16 unit = valueParts && valueParts[ 3 ] || ( isAutoPx( prop ) ? "px" : "" ),
17
18 // Starting value computation is required for potential unit mismatches
19 initialInUnit = elem.nodeType &&
20 ( !isAutoPx( prop ) || unit !== "px" && +initial ) &&
21 rcssNum.exec( jQuery.css( elem, prop ) );
22
23 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
24
25 // Support: Firefox <=54 - 66+
26 // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
27 initial = initial / 2;
28
29 // Trust units reported by jQuery.css
30 unit = unit || initialInUnit[ 3 ];
31
32 // Iteratively approximate from a nonzero starting point
33 initialInUnit = +initial || 1;
34
35 while ( maxIterations-- ) {
36
37 // Evaluate and update our best guess (doubling guesses that zero out).
38 // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
39 jQuery.style( elem, prop, initialInUnit + unit );
40 if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {
41 maxIterations = 0;
42 }
43 initialInUnit = initialInUnit / scale;
44
45 }
46
47 initialInUnit = initialInUnit * 2;
48 jQuery.style( elem, prop, initialInUnit + unit );
49
50 // Make sure we update the tween properties later on
51 valueParts = valueParts || [];
52 }
53
54 if ( valueParts ) {
55 initialInUnit = +initialInUnit || +initial || 0;
56
57 // Apply relative offset (+=/-=) if specified
58 adjusted = valueParts[ 1 ] ?
59 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
60 +valueParts[ 2 ];
61 if ( tween ) {
62 tween.unit = unit;

Callers 2

effects.jsFile · 0.90
css.jsFile · 0.90

Calls 2

isAutoPxFunction · 0.90
currentValueFunction · 0.50

Tested by

no test coverage detected