使用 jQuery 根据 Font-Family 更改正文字体大小 [英] Changing Body Font-Size based on Font-Family with jQuery
问题描述
我正在尝试使用 Myriad Pro 作为 Arial 的主要字体,例如像这样的后备字体:
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";
我想在选择 Arial 或 Helvetica 时更改字体大小.这是我在 jQuery 中所拥有的,但它不起作用:
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 没有官方支持的字体检测方式,但这个库是一个不错的解决方法:http://www.lalit.org/lab/javascript-css-font-detect
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');
}
});
另请注意,您应该只更改 font-size
属性.如果更改 font
属性,则会覆盖字体大小和字体系列.
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.
这篇关于使用 jQuery 根据 Font-Family 更改正文字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!