jQuery学习笔记3--网页字体变大变小
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jQuery学习笔记3--网页字体变大变小,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1745字,纯文字阅读大概需要3分钟。
内容图文
效果图:
js代码
<script type="text/javaScript">
$(function(){
$(".msg_caption span").click(function(){ //当文档加载完毕后,为所有的<span>元素绑定单击事件
var thisEle = $("#para").css("font-size"); //获取ID为“para”元素的大小
var textFontSize = parseFloat(thisEle , 10);//或许返回值用parseFloat()方法去掉单位,第二个值表示10进制
var unit =thisEle.slice(-2); //或许单位 , slice指定字符串应该从倒数第2个字符开始。
var cName =$(this).attr("class"); //获取当前的class
if(cName == "bigger fl") { //if语句判断当前被点击的<span>元素的Class是否为 boigger
textFontSize += 2; //是的话字体变量增加2px
}else{
textFontSize -= 2; //字体变量减少2px
}
$("#para").css("font-size" , textFontSize + unit ); //再次获取para的字体值并且带上单位
});
});
</script>
HTML代码
<div class="msg">
<div class="msg_caption">
<span class="bigger fl">放大</span>
<span class="smaller fl ">缩小</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-align: center; margin-right: 20px; font-size: 12px; cursor: pointer;}
</style>
原文:http://www.cnblogs.com/qdmaomao/p/4549033.html
内容总结
以上是互联网集市为您收集整理的jQuery学习笔记3--网页字体变大变小全部内容,希望文章能够帮你解决jQuery学习笔记3--网页字体变大变小所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。