JQuery: code example for setting the font size and jquery font size
JQuery:
Setting the font size on a webpage is a common operation. The following describes how to implement this function through code examples.
The Code is as follows:
<! DOCTYPE html>
The above Code meets our requirements to achieve the amplification and reduction of text content. The following describes the implementation process.
I. Code comments:
1. $ (function () {}). After the text structure is fully loaded, run the code in the function.
2. $ ("span"). click (function () {}), register the click event handler function for the span element.
3. var thisEle = $ ("# para" ).css ("font-size"), get the text font size under the para element with the id attribute value.
4. var textFontSize = parseFloat (thisEle, 10), convert the font size to a numeric value type.
5. var unit = thisEle. slice (-2): truncates the string, that is, the last two digits, that is, the unit (px ).
6. var cName = $ (this). attr ("class") to obtain the class attribute value of the currently clicked span element.
7. if (cName = "bigger") {textFontSize + = 2 ;}, if you click the zoom in button, the font is enlarged.
8. $ ("# para" ).css ("font-size", textFontSize + unit), set the font size.
Ii. Related reading:
1. For details about click events, see click events in jQuery.
2. For details about the css () function, see the css () method section of jQuery.
3. For the parseFloat () function, see section 1 of parseFloat () method in javascript.
4. For details about the slice () function, refer to slice () method 1 of the String object in javascript.
5. For more information about the attr () function, see the attr () method section of jQuery.
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 12398.
For more information, see: http://www.softwhy.com/jquery/