网页字体大小

<!DOCTYPE html>
<html>
<head>
<title>网页字体大小</title>
<script type="text/javascript" src="js/jquery-3.2.0.min.js"></script>
<style type="text/css">
.msg{
width: 500px;
border:1px solid #666;
margin:0 auto;
padding: 10px;
}
.msg_caption{
height: 35px;
}
.msg_caption .bigger,.msg_caption .smaller{
background-color: blue;
padding: 0 10px;
color:#fff;
cursor:pointer;
}
</style>
</head>
<body>
<div class="msg">
<div class="msg_caption">
<span class="bigger">变大</span>
<span class="smaller">变小</span>
<span class="fontSize"></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.
</p>
</div>
</div>
<script type="text/javascript">
$(function(){

$(".msg_caption span").click(function() {
$(".fontSize").remove();
var $thisEle=$("#para").css("font-size");//获取font-size的值
var $textFontSize=parseInt($thisEle,10);//用parseInt()方法去掉单位
var unit=$thisEle.slice(-2);//截取单位
var cName=$(this).attr("class");
if(cName == "bigger"){
if($textFontSize <=28)
$textFontSize +=2;
}else if(cName =="smaller"){
if($textFontSize >=12)
$textFontSize -=2;
}
$("#para").css("font-size",$textFontSize+unit);
$(".smaller").after("<span class='fontSize'>当前的字体是"+$textFontSize+unit+"号</span>")
});

})
</script>
</body>
</html>

注意:

1.parseInt()方法的第二个参数表示进制,代码中表示十进制。、

2.parseInt()方法返回字符串中从指定的字符开始的一个子字符串。

转载于:https://www.cnblogs.com/linjing-blog/p/6701415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值