使用jQuery知道@ font-face字体何时加载? [英] Using jQuery to know when @font-face fonts are loaded?

查看:1431
本文介绍了使用jQuery知道@ font-face字体何时加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用@ font-face,我讨厌Firefox显示默认字体,等待加载@ font-face字体,然后替换它。因此,整个页面都会以新字体闪烁。

I am using @font-face and I hate that Firefox shows the default font, waits to load the @font-face font, then replaces it. So the whole page flashes with the new font.

Webkit浏览器只是在加载字体之前不显示文本,并且它的外观更清晰。

Webkit browsers just don't display the text until the font is loaded and it is a much cleaner look.

因此,我想知道jQuery是否可以帮助我知道页面上的所有数据何时加载,包括@ font-face文件,以便我可以显示我的文本?是否有一个jQuery方法告诉我什么时候加载了?

So, I am wondering if jQuery could help me to know when all data on the page is loaded, including the @font-face file, so that I can then show my text? Is there a jQuery method that tells me when everything is loaded?

推荐答案

基本上我只是把我的文本设置为:

Ok, it was pretty easy. Basically I just set my text to:

a.main {visibility: hidden;}

,然后添加:

$(window).bind("load", function() {
       $('#nav a.main').addClass('shown');
});

然后确保我的css文件中还包含以下内容:

Then make sure that the following is also in my css file:

a.main.shown {visibility: visible;}

这篇关于使用jQuery知道@ font-face字体何时加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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