动态加载字体html jquery [英] dynamically load fonts html jquery
问题描述
我正在一个网站上工作,允许用户输入一些文本并将其拖拽到位,等等。我已经到了一个我想提供字体选择的地步。我可以动态加载字体,而不是一次全部?例如,用户输入他们的文本,并选择使用通用字体1是否有可能使用jQuery加载该字体?这样,我可以提供一大堆字体,而不会在页面加载时加载全部字体。此外,我希望使用谷歌网页字体,但不是必须的。为了清楚起见,我正在使用一些自定义字体,它们加载得很好。
I am working on a site that allows the user to enter some text and drag it into position, etc. I have gotten to a point I would like to offer a choice of fonts. Can I dynamically load fonts instead of all at once? For instance, the user enters their text and chooses to use "Generic Font 1" is it possible to load that font with jquery? That way I can offer a bunch of fonts without loading them all when the page loads. Also I was hoping to use google web fonts, but not a must. Just for clarity, I am currently using a couple of custom fonts and they load just fine.
再一次,谢谢...
Todd
Once again, Thank you... Todd
推荐答案
这是我最近写的一个函数,用于动态添加Google web字体...
Here's a function I wrote recently for adding Google web fonts dynamically...
function addGoogleFont(FontName) {
$("head").append("<link href='https://fonts.googleapis.com/css?family=" + FontName + "' rel='stylesheet' type='text/css'>");
}
addGoogleFont("Junge"); // for example
之后,您只需通过 font-family 就像通常那样。
After that you just apply the font via font-family
as you normally would.
这篇关于动态加载字体html jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!