JQuery Source Analysis CSS Operation principle

Source: Internet
Author: User
Tags readable

Jquery.fn.css Gets the property value "$ (...) of the first element in the element that matches the current jquery." CSS (cssname), note that this cssname can be an array "or set the style value" $ (...) for each element that the current jquery matches. CSS (Cssname,value)/$ (...). CSS (obj) "; The

can see that the function is called directly inside the jquery.access to handle. Access breaks down elements that match the jquery object of the current multiple elements into a single element called the callback function (Elem, name, value) in the second argument, and if the argument name is an object, Access internal decomposition name recursive calls each of the Key/value key values for name

source

Jquery.fn.css: function ( name, value )  {    // Access decomposes the current jquery object into a single element to invoke the callback function ( elem, name, value ) in the second argument,      //If the argument name is an object, access internal decomposition name recursive call processes each of the name's key/value key value pairs     return  Jquery.access ( this, function ( elem, name, value )  {         var len, styles,         map
 = {},         i = 0;         //if the CSS feature name is an array, such as [' Left ', ' marginright ']          if  ( jquery.isarray ( name )  )  {   
         styles = getstyles ( elem );             len =&nbSp;name.length;             //$.css () to obtain the corresponding CSS feature value              for  ( ; i < len;  i++ )  {                 map[ name[ i ] ] = jquery.css ( elem, name[ i ], 
false, styles );             }       
      return map;        &NBSP}         //value A value then call $ . Style sets a single CSS value, and the value parameter has no value, and the corresponding CSS eigenvalue is obtained by $.CSS ()         return value
 !== undefined ?         jquery.style ( elem, name, value )  :         jquery.css ( elem, name );
    }, name, value, arguments.length > 1 ); }


This API is relatively simple, but careful analysis of the functions called inside will find a lot of knowledge. Behind Yi Yilai excavation.

First we see the function of Getstyles (elem) and look at his definition

if (window.getComputedStyle) {
getstyles = function (elem) {return
window.getComputedStyle (Elem,    NULL);
};
...
ie8-compatible
} else if (Document.documentElement.currentStyle) {
getstyles = function (elem) {
Retu    RN Elem.currentstyle;
};
...
}


Two different methods window.getComputedStyle and Elem.currentstyle. Then analyze them all.

A. window.getComputedStyle

Complete expression window.getComputedStyle (Elem,pseudo)

Elem:dom node, you must

Pseudo: Pseudo class, and only pseudo-element pseudo class, such as: After,::before,::first-letter,::first-line. The second argument "pseudo class" is required before the optional "Gecko 2.0 (Firefox 4/thunderbird 3.3/seamonkey 2.1)"

Description: This function is taken out of the CSS after the final use of the CSS property value "which does not include positional relationships Left/right/top/bottom attribute values, such as left:10%, then through the getComputedStyle get left or" 10% "(Safari 5.1.7 's margin-right returns a percentage, which requires special handling). Read-only. Good support in modern browsers, no support for ie8-

Examples (This example will go through the full text):

<style>
#myList {
height:100px;
}
#myList: after{
Content: ' A ';
height:100px;
}
</style>

<ul id= "myList" style= ' width:50%;left:666px; ><li>test</li></ul>
<ul id= "MyList2" style= ' width:50%;left:111px; ><li>test2</li></ul>

The getComputedStyle value is the computed value (for example, the percentages are converted to pixels), and the following example


The width 50% is converted to pixels.

The second argument in getComputedStyle is only a pseudo-element artifact that works, as in the following instance


As the above figure shows, as long as the following pseudo element does not or does not pass the pseudo element pseudo class This parameter, then obtains is also the first parameter corresponding element's getComputedStyle value. The left and. Content properties can testify in the image above.

getComputedStyle gets a read-only group object, each element of the array is a CSS style name, and the read-only group object has a property that corresponds to one by one of each element in the array to hold the value of the CSS style. Let's look at the structure first (window.getComputedStyle (document.getElementById (' myList '), NULL)



But because we don't support ie8-, we need a way that IE8 can support. This is IE's own dongdong Elem.currentstyle


B. Elem.currentstyle


Elem.currentstyle is also a read-only object.

The difference between Elem.currentstyle and getComputedStyle

1. Elem.currentstyle is a pure object in ie8-, without the structure of the class array, the CSS style name cannot be obtained by style[n], and Elem.currentstyle is a class array object in ie9+.

2. The style obtained by Elem.currentstyle is a final CSS style, but not a calculated style, such as the previous example

getComputedStyle's width results in pixel value 632px


And the result of the Elem.currentstyle is that the percentage value set is 50%


3. Differences in style names, such as for float properties, ie8-Currentstyle is stylefloat


And Firefox getComputedStyle is cssfloat and float "recommended not to use, browser retention, but also non-standard methods, browsers can not support" coexist


In Chrome, getComputedStyle is shown as float, which is actually not recommended for use by float, browser retention, and non-standard methods, browsers are not supported and cssfloat can be obtained



And IE9 are both Cssfloat and stylefloat.

So the way jQuery gets the float property is "float": jQuery.support.cssFloat? "Cssfloat": "Stylefloat"


C. elem.style


Elem.style and window.getComputedStyle (Elem,pseudo) and Elem.currentstyle comparisons

Elem.style is the inline style that gets the elem. This is one of the different places than window.getComputedStyle (Elem,pseudo) and Elem.currentstyle.


Style results are readable and writable, while getComputedStyle and currentstyle results are read-only.

The style result is a result of no calculation, similar to Currentstyle, getComputedStyle is the computed result. The Style.width value in the following figure is 50%, not the pixel value




D. Modern browsers gets the value of a style in a style sheet--getpropertyvalue


GetPropertyValue (ClassName) is a modern browser (Ie9+,firefox,chrome ...) A property method for a style sheet. So as long as it's a modern browser, the style sheet style obtained above Getcomputedstyle/currentstyle/style three ways can use this method to get the style value. such as Style.getpropertyvalue ("float").

Note that classname is a direct attribute name (such as "Background-color"). is "float" rather than "css-float" or "cssfloat".


If you obtain a float value by using property capture, you need to convert to "cssfloat" or "stylefloat", such as


This is a bit of a toss.

And since ie8-does not support this method, ie8-directly uses the property acquisition method


Ie8-'s currentstyle also supports another way to get a property: Style.getattribute (ClassName).

It should be noted that the classname can be either a direct attribute name or a hump (such as "Background-color" or "BackgroundColor").


So, we have two ways of dealing with styles for compatibility

1. Combined with GetPropertyValue (ClassName) and GetAttribute (ClassName), because both className can be direct property names

2. Using the property capture method Style[classname] But note that property names need to be compatible, for example: "Float" needs to be replaced by "cssfloat" or "stylefloat".

and jquery's processing is to choose the second way.

Here, though jquery uses the second approach, there is a property that uses property to get it to fail, which is the "filter" attribute of the wonderful work. This property must use GetPropertyValue to get the correct

Use the table to summarize the relative usage of CSS property acquisition


Characteristics getComputedStyle Currentstyle Style
Browser support situation Ie9+,chrome,firefox ... Ie All
Readable to write Read-only Read-only Readable to write
Whether to calculate the final value (for example, percentages, proportions are calculated as real pixel values) Is Whether Whether
(External style sheet + internal style sheet + inline style) end result Is Is No (inline style only)
Property capture Methods Style.name and Style[name] Support (Except for "Filter" property) Support Support
Supported methods for obtaining CSS property values GetPropertyValue Ie8-supports only getattribute;ie9+ support GetPropertyValue and GetAttribute ("filter") Ie8-supports only getattribute;ie9+ support GetPropertyValue and GetAttribute ("filter"); Other browsers only support GetPropertyValue
Outstanding Advantages Standardize and support pseudo elements (e.g.: after) to obtain computed results
Readable to write





Then continue to analyze the source code:

Now that you know the various ways to get a CSS style sheet, next look at a calculated merit function Curcss = functions (Elem, Name, _computed) corresponding to the specified CSS style name. The difficulty is that the value obtained through Currentstyle and getComputedStyle may be a percentage or a relatively worthwhile time, and we need to simulate and compute the real value. Process comparison point list, see Source code annotation

Note: We included "window" in window.getComputedStyle//Because node.js in js&nbsp;dom would be terminated without him if&nbsp; (&nbsp; window.getcomputedstyle&nbsp;) &nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;getstyles&nbsp;=&nbsp;function (&nbsp;elem &nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;window.getcomputedstyle (&nbsp;elem,
&nbsp;null&nbsp;);
  &nbsp;&nbsp;&nbsp;&nbsp;}; Curcss&nbsp;=&nbsp;function (&nbsp;elem,&nbsp;name,&nbsp;_computed&nbsp;) &nbsp;{var&nbsp;width,&nbsp;minwidth, &nbsp;maxwidth, computed&nbsp;=&nbsp;_computed&nbsp;| | &nbsp;getstyles (&nbsp;elem&nbsp;),//&nbsp;getpropertyvalue only used ret&nbsp;=&nbsp; in IE9 &nbsp;.css (' filter ') Computed&nbsp;?&nbsp;computed.getpropertyvalue (&nbsp;name&nbsp;) &nbsp;| |
    &nbsp;computed[&nbsp;name&nbsp;]&nbsp;:&nbsp;undefined, style&nbsp;=&nbsp;elem.style; if&nbsp; (&nbsp;computed&nbsp;) &nbsp;{if&nbsp; (&nbsp;ret&nbsp;===&nbsp; "" &nbsp;&amp;&amp;&nbsp;!jquery.contains (&nbsp;elem.ownerDocument,&nbsp;elem&nbsp;) &nbsp;) &nbsp;{ret&Nbsp;=&nbsp;jquery.style (&nbsp;elem,&nbsp;name&nbsp;); //&nbsp;chrome&nbsp;&lt;&nbsp;17&nbsp;and&nbsp;safari&nbsp;5.0 calculates margin-right//&nbsp;safari using "calculated results" instead of "used values"
      &nbsp;5.1.7&nbsp; (latest) percent return but we need pixel values, which violate the Cssom draft//http://dev.w3.org/csswg/cssom/#resolved-values//simulation calculation if&nbsp; (&nbsp;rnumnonpx.test (&nbsp;ret&nbsp;) &nbsp;&amp;&amp;&nbsp;rmargin.test (&nbsp;name&nbsp;) &nbsp;)
        &nbsp;{//Save the original value width&nbsp;=&nbsp;style.width;
        minwidth&nbsp;=&nbsp;style.minwidth;
        maxwidth&nbsp;=&nbsp;style.maxwidth; Add a new value to get the calculated value, such as when MarginRight is 10%, by putting a width of 10%, and then through the computed.width can get 10% corresponding px width style.minwidth&nbsp;=&nbsp;
        style.maxwidth&nbsp;=&nbsp;style.width&nbsp;=&nbsp;ret;
        ret&nbsp;=&nbsp;computed.width;
        Restore the changed value style.width&nbsp;=&nbsp;width;
        style.minwidth&nbsp;=&nbsp;minwidth;
      style.maxwidth&nbsp;=&nbsp;maxwidth;
  }} return&nbsp;ret;
}; Low version IE compatible}&nbsp;else&nbsp;if&nbsp. (&nbsp;document.documentElement.currentStyle&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;getStyles&nbsp;=&nbsp; function (&nbsp;elem&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;elem.currentstyle
;
&nbsp;&nbsp;&nbsp;&nbsp;}; &nbsp;&nbsp;&nbsp;&nbsp;curcss&nbsp;=&nbsp;function (&nbsp;elem,&nbsp;name,&nbsp;_computed&nbsp;) &nbsp;{&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;left,&nbsp;rs,&nbsp;rsleft, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;computed&nbsp;=&nbsp;_computed&nbsp;| | &nbsp;getstyles (&nbsp;elem&nbsp;), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret&nbsp;=&nbsp;computed &nbsp;?&nbsp;computed[&nbsp;name&nbsp;]&nbsp;:&nbsp;undefined, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
style&nbsp;=&nbsp;elem.style; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//here avoid setting null characters for RET &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;//so we don't default to "Auto" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;ret&nbsp;==&nbsp;null &nbsp;&amp;&amp;&nbsp;style&nbsp;&amp;&amp;&nbsp;style[&nbsp;name&nbsp;]&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret&nbsp;=&nbsp;style[&nbsp;name&nbsp;]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp; we're going to convert him to pixels in a weird ending number (like 1em) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;//&nbsp; but not positional properties, they should be proportional to the parent element, and we can't measure the proportions of the parent element, because he could be a stack of scales (like &lt;div&nbsp;style= ' left:10% ' &gt;
&lt;p&nbsp;style= ' left:20% ' &gt;&lt;span&nbsp;style= ' left:20% ' &gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;), could not be calculated at all &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;rnumnonpx.test (&nbsp;ret&nbsp;) &nbsp;&amp;&amp; &nbsp;!rposition.test (&nbsp;name&nbsp;) &nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//Save the original value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;left&nbsp;=
&nbsp;style.left; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs&nbsp;=&nbsp;elem.runtimestyle; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rsLeft&nbsp;=&nbsp;rs&nbsp;&amp;&amp;
&nbsp;rs.left; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//add a new value to get calculated value &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;rsLeft&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.left&nbsp;=&nbsp;
Elem.currentStyle.left; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style.left&nbsp;=&nbsp;name&nbsp;===&nbsp; "FontSize" &nbsp;?&nbsp; "1em"
&nbsp;:&nbsp;ret; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret&nbsp;=&nbsp;style.pixelleft&nbsp;+
&nbsp; "PX"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//restore the changed value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style.left&nbsp;=&nbsp;left;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;rsLeft&nbsp;) &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.left&nbsp;=
&nbsp;rsLeft; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ret&nbsp;===&nbsp; "&nbsp;?&nbsp;"
Auto "&nbsp;:&nbsp;ret;
&nbsp;&nbsp;&nbsp;&nbsp;}; }



According to the last processing of the JQUERY.FN.CSS function

return value!== undefined?
        Jquery.style (elem, Name, value):
         jquery.css (elem, name);

You know the two key low-level api:jQuery.style and jquery.css that CSS handles. The

has previously analyzed that only. Style is readable, and, similarly, the Jquery.style function is also used to read and write inline styles. The processing process for the Jquery.style is

1. Fixed CSS feature name saved as OrigName, the name that really can be recognized by the browser is saved as named.
2. Find csshooks for name or OrigName.
3. If the value is set (there is a pass value parameter), set it. The more special processing is that value can be a cumulative string (such as: "+ +") first by jquery.css the original value to be computed. If value is a number, you need to see if the PX unit is added depending on the situation. If there is a corresponding csshooks also need special treatment and so on.
4. If you are getting a value (without passing the value parameter), there are two situations in which a hooks is obtained by hooks or directly style[name].

Source

Sets or gets a style eigenvalue for a DOM node jquery.style:&nbsp;function (&nbsp;elem,&nbsp;name,&nbsp;value,&nbsp;extra&nbsp;) &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;//text and annotation nodes cannot set style feature values &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;!elem&nbsp;| | &nbsp;elem.nodetype&nbsp;===&nbsp;3&nbsp;| | &nbsp;elem.nodetype&nbsp;===&nbsp;8&nbsp;| | &nbsp;!elem.style&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;//modifies the CSS feature name to fit the current browser &nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;ret,&nbsp;type,&nbsp;hooks &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;origname&nbsp;=&nbsp;jquery.camelcase (&nbsp;name&nbsp;), &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style&nbsp;=&nbsp;elem.style; &nbsp;&nbsp;&nbsp;&nbsp;//jquery.cssprops cache queried CSS feature name for subsequent easy to find use &nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;=&nbsp; jquery.cssprops[&nbsp;origname&nbsp;]&nbsp;| | &nbsp; (&nbsp;jquery.cssprops[&nbsp;origname&nbsp;]&nbsp;=&nbsp;vendorpropname &nbsp;style,&nbsp;origName&nbsp;
) &nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;//gets a prefix version of the hooks orNo prefix version of hooks &nbsp;&nbsp;&nbsp;&nbsp;hooks&nbsp;=&nbsp;jquery.csshooks[&nbsp;name&nbsp;]&nbsp;| |
&nbsp;jQuery.cssHooks[&nbsp;origName&nbsp;]; &nbsp;&nbsp;&nbsp;&nbsp;//If you are setting a value for a CSS feature name &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; &nbsp;value&nbsp;!==&nbsp;undefined &nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;=&nbsp;typeof&nbsp;value; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;convert&nbsp;relative&nbsp;number&nbsp;strings&nbsp; (+=&nbsp;or &nbsp;-=) &nbsp;to&nbsp;relative&nbsp;numbers.&nbsp; #7345 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//
Rrelnum&nbsp;=&nbsp;new&nbsp;regexp (&nbsp; "^ ([+-]) = (" &nbsp;+&nbsp;core_pnum&nbsp;+&nbsp; ")",&nbsp; "I" &nbsp; " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//converts the relative number of strings +=/-= to the corresponding number &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;if&nbsp; (&nbsp;type&nbsp;===&nbsp; "string" &nbsp;&amp;&amp;&nbsp; (Ret&nbsp;=&nbsp;rrelnum.exec ( &nbsp;value&nbsp;)) &nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//(+&nbsp;+&nbsp;1) &nbsp;==&nbsp;1; (-&nbsp;+&nbsp;1) &nbsp;==&nbsp;-1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;=&nbsp; (&nbsp;ret[1]&nbsp;+&nbsp;1&nbsp;) &nbsp;*&nbsp;ret[2]
&nbsp;+&nbsp;parsefloat (&nbsp;jquery.css (&nbsp;elem,&nbsp;name&nbsp;) &nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Fixes&nbsp;bug&nbsp; #9237
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;=&nbsp; "Number";
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//nan and Null are not available &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;value&nbsp;==&nbsp;null&nbsp;| | &nbsp;type&nbsp;===&nbsp; "Number" &nbsp;&amp;&amp;&nbsp;isnan (&nbsp;value&nbsp;) &nbsp;) &nbsp;{&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Except for CSS features that are not set to pixel units, the rest is addedPlus "px" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;type&nbsp;===&nbsp; "number" &nbsp;&amp; &amp;&nbsp;!jQuery.cssNumber[&nbsp;origName&nbsp;]&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;+=&nbsp; "px"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//
support.clearclonestyle&nbsp;=&nbsp;div.style.backgroundclip&nbsp;===&nbsp; "Content-box"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//div.style.backgroundclip is not "Content-box" mode and &nbsp;&nbsp;&nbsp; The value set by &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//is empty background ... Set it to inherit the parent node style &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Fixes&nbsp; #8908,&nbsp; It is more accurate to set the default value for each problem feature, but it will call at least 8 times function &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;! jquery.support.clearclonestyle&nbsp;&amp;&amp;&nbsp;value&nbsp;===&nbsp; "" &nbsp;&amp;&amp;&nbsp;name.indexof (" Background ") &nbsp;===&nbsp;0&nbsp;) &nbsp;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style[&nbsp;name&nbsp;]&nbsp;=&nbsp; "Inherit"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If the hook is provided, set the value with the hook, otherwise set the top value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;!hooks&nbsp;| | &nbsp;! ("Set" &nbsp;in&nbsp;hooks) &nbsp;| | &nbsp; (Value&nbsp;=&nbsp;hooks.set (&nbsp;elem,&nbsp;value,&nbsp;extra&nbsp;)) &nbsp;!==&nbsp;undefined&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//When the value you want to set is an invalid value ie throws an exception &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Fixes&nbsp;bug&nbsp; #5509 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style[&nbsp;name&nbsp;]&nbsp;=&nbsp;value; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch (e) &nbsp;{} &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;//Get value &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If a hook is provided, use the hook to take the value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; ( &nbsp;hooks&nbsp;&amp;&amp;&nbsp; "Get" &nbsp;in&nbsp;hooks&nbsp;&amp;&amp;&nbsp; (Ret&nbsp;=&nbsp;hooks.get ( &nbsp;elem,&nbsp;false,&nbsp;extra&nbsp;)) &nbsp;!==&nbsp;undefined&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ret; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;
Other cases take value from the Style object &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;style[&nbsp;name&nbsp;]; &NBSP;&NBSP;&NBSP;&NBSP}//Returns a CSS feature name, which may be a feature name function&nbsp;vendorpropname that the vendor has added a prefix (&nbsp;style,&nbsp;name &nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;//short name not added vendor prefix &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;name&nbsp;in&nbsp; style&nbsp;) &nbsp;{return&nbsp;name;&nbsp} &nbsp;&nbsp;&nbsp;&nbsp;//Check the vendor prefix name
&nbsp;&nbsp;&nbsp;&nbsp;//cssPrefixes&nbsp;=&nbsp;[&nbsp; "Webkit",&nbsp; "O",&nbsp; "Moz",&nbsp; "MS" &NBSP;]
&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;capname&nbsp;=&nbsp;name.charat (0). toUpperCase () &nbsp;+&nbsp;name.slice (1), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;origname&nbsp;=&nbsp;name, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;i&nbsp;=&nbsp;cssPrefixes.length; &nbsp;&nbsp;&nbsp;&nbsp;while&nbsp; (&nbsp;i--&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
name&nbsp;=&nbsp;cssprefixes[&nbsp;i&nbsp;]&nbsp;+&nbsp;capname; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;name&nbsp;in&nbsp;style&nbsp;) &nbsp;{return
&nbsp;name;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;origName; }



jquery.css processing is also relatively simple

1. Fixed CSS feature name saved as OrigName, the name that really can be recognized by the browser is saved as "
2". If a corresponding csshooks is present, otherwise the Curcss method is used to get the style value
3. The default value for the acquired style value is to be handled, for example, the value of the CSS style fontweight default is "normal" corresponding to 400.

Source

Get the CSS eigenvalue corresponding to name Css:&nbsp;function (&nbsp;elem,&nbsp;name,&nbsp;extra,&nbsp;styles&nbsp;) &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;var&nbsp;num,&nbsp;val,&nbsp;hooks, &nbsp;&nbsp;&nbsp;&nbsp;origname&nbsp;=&nbsp;jquery.camelcase (
&nbsp;name&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;//fixed name &nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;=&nbsp;jquery.cssprops[&nbsp;origname&nbsp;] &nbsp;| | &nbsp; (&nbsp;jquery.cssprops[&nbsp;origname&nbsp;]&nbsp;=&nbsp;vendorpropname (&nbsp;elem.style,&nbsp;origname
&nbsp;) &nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;//gets a prefix version of the hooks or a hooks with no prefix version &nbsp;&nbsp;&nbsp;&nbsp;hooks&nbsp;=&nbsp;jquery.csshooks[ &nbsp;name&nbsp;]&nbsp;| |
&nbsp;jQuery.cssHooks[&nbsp;origName&nbsp;]; &nbsp;&nbsp;&nbsp;&nbsp;//extract value from Hook &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;hooks&nbsp;&amp;&amp;&nbsp; "Get" &nbsp;in&nbsp;hooks&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;hooks.get (
&nbsp;elem,&nbsp;true,&nbsp;extra&nbsp;); &NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;//other cases using CURCSS value &NBSP;&NBSP;&Nbsp;&nbsp;if&nbsp; (&nbsp;val&nbsp;===&nbsp;undefined&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;val&nbsp;=&nbsp;curcss (&nbsp;elem,&nbsp;name,&nbsp;styles&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;//cssnormaltransform&nbsp;=&nbsp;{letterspacing:&nbsp;0, fontweight:&nbsp;400} &nbsp;&nbsp;&nbsp;&nbsp;//converts "normal" to calculated value &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp; (&nbsp;val&nbsp; ===&nbsp; "Normal" &nbsp;&amp;&amp;&nbsp;name&nbsp;in&nbsp;cssNormalTransform&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val&nbsp;=&nbsp;cssNormalTransform[&nbsp;name&nbsp;]; &NBSP;&NBSP;&NBSP;&NBSP} &nbsp;&nbsp;&nbsp;&nbsp;//forces or provides a qualifier and Val looks like a number to force into a number and returns &NBSP;&NBSP;&NBSP;&NBSP;IF &nbsp; (&nbsp;extra&nbsp;===&nbsp; "" &nbsp;| | &nbsp;extra&nbsp;) &nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;=&nbsp;parsefloat (&nbsp;val
&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;extra&nbsp;===&nbsp;true&nbsp;| | &nbsp;jquery.isnumeric (&nbsp;num&nbsp;) &nbsp;?&nbsp;num&nbsp;| |
&nbsp;0&nbsp;:&nbsp;val;
&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;val; }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.