放大缩小html文字,jquery放大缩小文字

这段代码演示了如何使用jQuery实现文字的放大和缩小功能。当用户点击带有类名'c_big'或'c_small'的span元素时,会根据当前文字的大小动态调整#title元素的字体大小。如果文字大小小于22px,点击'c_big'会增加2px;如果文字大小大于12px,点击'c_small'会减小2px。该功能在网页的#content区域中运行。
摘要由CSDN通过智能技术生成
jquery放大缩小文字

$(function(){

$("span").click(function(){

var theSize = $("#title").css("font-size");

var theTitleSize =parseFloat(theSize,10);//获取字体的大小

var units = theSize.slice(-2); //获取单位

var c_name = $(this).attr("class");//获取属性

if(c_name =="c_big"){//如果是放大则增大文字

if(theTitleSize <= 22){//判断大小,如果小于22px则减少

theTitleSize+=2;

}

}else if(c_name =="c_small"){//如果是缩小则缩小文字

if(theTitleSize >= 12){//判断大小,如果大于12px则减少

theTitleSize-=2;

}

}

$("#title").css("font-size",theTitleSize + units);//添加样式

});

});

#content{

width:300px;

height:450px;

background:#000000;

}

.c_big{

width:30px;

height:15px;

background:#00F;

border:1px;

margin:20px 20px;

}

.c_small{

width:30px;

height:15px;

background:#00F;

border:1px;

margin:10px 20px;

}

#title{

color:#FFFFFF;

}

放大 缩小

举得起放得下的叫举重,举得起放不下的叫负重。可惜,大多数人的爱情,都是负重的。

If you can hold something up and put it down, it is called weight-lifting; if you can hold something up but can never put it down,it's called burden-bearing. Pitifully, most of people are bearing heavy burdens when they are in love.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值