基于Font-Family使用jQuery更改body字体大小 [英] Changing Body Font-Size based on Font-Family with jQuery

查看:794
本文介绍了基于Font-Family使用jQuery更改body字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Myriad Pro作为我的主要字体与Arial和诸如这样的后退:

  font:13pxMyriad Pro,Helvetica,Arial,sans-serif; 

我想在选择Arial或Helvetica时更改字体大小。这是我在jQuery,但它不工作:

  $(function(){
if (body)css(font)==Arial){
$(body)css(font,10px);
};
});我感谢您的时间,帮助和慷慨:)


=h2_lin>解决方案

JavaScript没有正式支持的检测字体的方法,但这个库是一个体面的解决方法: http://www.lalit.org/lab/javascript-css-font-detect



使用此检测器,您可以使用:

  $(function(){
var fontDetector = new Detector();
if(fontDetector.test('Arial')){
$('body')。css('font-size','10px');
}
});

另请注意,您只应更改 font-size 属性。如果更改字体属性,则会覆盖字体大小和字体系列。


I'm trying to use Myriad Pro as my primary font with Arial and such as a fall-back like so:

font: 13px "Myriad Pro", "Helvetica", "Arial", "sans-serif";

I want to change the font-size when Arial or Helvetica are selected. This is what I have in jQuery but it does not work:

$(function(){
  if ($("body").css("font") == "Arial") {
    $("body").css("font", "10px");
};
});

I appreciate your time, help and generosity :)

解决方案

JavaScript doesn't have an officially supported way of detecting fonts, but this library is a decent workaround: http://www.lalit.org/lab/javascript-css-font-detect

Using this detector, you can then use:

$(function(){
  var fontDetector = new Detector();
  if(fontDetector.test('Arial')){
    $('body').css('font-size', '10px');
  }
});

Also note that you should only change the font-size property. If you change the font property, you overwrite both your font size and your font families.

这篇关于基于Font-Family使用jQuery更改body字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆