jQuery实现自动调整字体大小的方法
作者:bea
本文实例讲述了jQuery实现自动调整字体大小的方法。分享给大家供大家参考。具体分析如下: 这里使用一个jQuery函数,自动更改元素中的文本的字体大小。 $.fn.fontfit = function(max) { var max_size = 18; if (typeof(max) == "undefined") max = max_size; $(this).wrapInner('<div id="fontfit"></div>'
本文实例讲述了jQuery实现自动调整字体大小的方法。分享给大家供大家参考。具体分析如下:
这里使用一个jQuery函数,自动更改元素中的文本的字体大小。
$.fn.fontfit = function(max) {
var max_size = 18;
if (typeof(max) == "undefined")
max = max_size;
$(this).wrapInner('<div id="fontfit"></div>');
var dheight = $(this).height();
var cheight = $("#fontfit").height();
var fsize = (($(this).css("font-size")).slice(0,-2))*1;
while(cheight<dheight && fsize<max) {
fsize+=1;
$(this).css("font-size",fsize+"px");
cheight = $("#fontfit").height();
}
while(cheight>dheight || fsize>max) {
fsize-=1;
$(this).css("font-size",fsize+"px");
cheight = $("#fontfit").height();
}
$("#fontfit").replaceWith($("#fontfit").html());
return this;
}
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
这里使用一个jQuery函数,自动更改元素中的文本的字体大小。
$.fn.fontfit = function(max) {
var max_size = 18;
if (typeof(max) == "undefined")
max = max_size;
$(this).wrapInner('<div id="fontfit"></div>');
var dheight = $(this).height();
var cheight = $("#fontfit").height();
var fsize = (($(this).css("font-size")).slice(0,-2))*1;
while(cheight<dheight && fsize<max) {
fsize+=1;
$(this).css("font-size",fsize+"px");
cheight = $("#fontfit").height();
}
while(cheight>dheight || fsize>max) {
fsize-=1;
$(this).css("font-size",fsize+"px");
cheight = $("#fontfit").height();
}
$("#fontfit").replaceWith($("#fontfit").html());
return this;
}
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- javascript验证邮件地址和MX记录的方法
- 详解JavaScript正则表达式中的global属性的使用
- Javascript 是你的高阶函数(高级应用)
- Javascript 高阶函数使用介绍
- jQuery预加载图片常用方法
- 简述JavaScript中正则表达式的使用方法
- 简介JavaScript中用于处理正切的Math.tan()方法
- 在JavaScript中使用开平方根的sqrt()方法
- JavaScript中的Math.sin()方法使用详解
- JavaScript中用于四舍五入的Math.round()方法讲解
- JavaScript中用于生成随机数的Math.random()方法
- JavaScript中的pow()方法使用详解
- 在JavaScript中使用对数Math.log()方法的教程
- JQuery工具函数汇总
- 原生js实现模拟滚动条
- jquery插件unobtrusive实现片段式加载
- js预加载图片方法汇总
- jquery实现兼容IE8的异步上传文件
- JavaScript中使用Math.floor()方法对数字取整