:
JS Code
<script type= "Text/javascript" >
$ (function () {
$ (". Msg_caption span"). Click (function () {////When the document has finished loading, bind the order event to all <span> elements
var Thisele = $ ("#para"). CSS ("font-size"); Gets the size of the ID "para" element
var textfontsize = parsefloat (Thisele, 10);//The return value is removed from the unit with the Parsefloat () method, and the second value represents 10 binary
var unit =thisele.slice (-2); Perhaps the unit, slice specifies that the string should start at the 2nd-lowest character.
var cName =$ (this). attr ("class"); Gets the current class
if (CName = = "bigger fl") {//if statement determines whether the class of the currently clicked <span> element is Boigger
Textfontsize + = 2; If so, the font variable is increased by 2px
}else{
Textfontsize-= 2; Font variables reduced by 2px
}
$ ("#para"). CSS ("Font-size", textfontsize + unit); Get the Para font value again and bring the unit
});
});
</script>
HTML code
<div class= "MSG" >
<div class= "Msg_caption" >
<span class= "bigger fl" > Zoom </span>
<span class= "smaller fl" > Zoom out </span>
</div>
<div>
<p id= "Para" >
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
</p>
</div>
</div>
<style type= "Text/css" >
a{text-decoration:none; coor: #000;}
. fl{Float:left;}
. fr{Float:right;}
. msg {width:500px; border:1px solid #ccc;}
. msg_caption {width:500px; overflow:hidden;}
. msg_caption span {display:block; width:50px; height:20px; line-height:20px; background: #666; color: #fff; Text-alig N:center; margin-right:20px; font-size:12px; Cursor:pointer;}
</style>
jquery Learning Note 3--Web page font size becomes smaller