当前位置:编程学习 > JS >>

jquery适时控制网页字体,无限制放大缩小

jquery适时控制网页字体,无限制放大缩小,你可又一直点击放大或缩小,字体一直会被放大或缩小,而不受限制,不过,似乎一直这么下去,也没什么意义,应该定义最大和最小的字体,仅供参考。
答案:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery适时控制网页字体,无限制放大缩小</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="http://www.zzzyk.com/ajaxjs/jquery1.3.2.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"){
					textFontSize += 2;
			}else if(cName == "smaller"){
					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>

上一个:用marquee和div+js实现无缝循环文字滚动效果
下一个:仿zol商城播报,仿新浪微博

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,