jQuery动态修改字体大小的方法
来源:爱站网时间:2019-12-18编辑:网友分享
JQuery动态字体大小修改代码是可以改变字体大小的代码,它适合在各种响应布局中显示文本,下文是爱站技术频道和大家介绍的jQuery动态修改字体大小的方法,一起来看看吧!
JQuery动态字体大小修改代码是可以改变字体大小的代码,它适合在各种响应布局中显示文本,下文是爱站技术频道和大家介绍的jQuery动态修改字体大小的方法,一起来看看吧!
运行效果截图如下:

完整代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
* { margin:0; padding:0; }
.msg {width:300px; margin:100px; }
.msg_caption { width:100%; overflow:hidden; margin-bottom:1px;}
.msg_caption span { display:block; float:left; margin:0 2px; padding:4px 10px; background:#898989; cursor:pointer;font-size:12px;color:white; }
.msg textarea{ width:300px; height:80px;height:100px;border:1px solid #000;}
</style>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("span").click(function(){
var thisEle = $("#para").css("font-size");
var textFontSize = parseFloat(thisEle , 10);
var unit = thisEle.slice(-2); //获取单位
var cName = $(this).attr("class");
if(cName == "bigger"){
if( textFontSize <= 22 ){
textFontSize += 2;
}
}else if(cName == "smaller"){
if( textFontSize >= 12 ){
textFontSize -= 2;
}
}
$("#para").css("font-size", textFontSize + unit);
});
});
</script>
</head>
<body>
<div class="msg">
<div class="msg_caption">
<span class="bigger" >放大</span>
<span class="smaller" >缩小</span>
</div>
<div>
<p id="para">
人生若只如初见,何事秋风悲画扇。
等闲变却故人心,却道故人心易变。
骊山语罢清宵半,泪雨霖铃终不怨。
何如薄幸锦衣郎,比翼连枝当日愿。
</p>
</div>
</div>
</body>
</html>
希望上述介绍的jQuery动态修改字体大小的方法对大家学习有帮助,不管是什么时候,修改字体大小是大家都需要学会的基本知识。
