jquery Learning Note 3--Web page font size becomes smaller

Source: Internet
Author: User

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

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.