AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

jQuery动态修改字体大小的方法【测试可用】

51自学网 http://www.wanshiok.com
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相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结

希望本文所述对大家jQuery程序设计有所帮助。


jQuery,动态修改,字体大小  
上一篇:Three.js快速入门教程  下一篇:Bootstrap菜单按钮及导航实例解析