jQuery - 检测自定义字体何时加载?

发布于 2024-12-19 02:56:35 字数 157 浏览 3 评论 0原文

我需要测量网站的导航以确定可用于我正在构建的功能的空间。我最近添加了自定义字体...

问题是我在加载新字体之前测量了导航。然后加载新字体并改变导航的宽度。然后我留下了不正确的宽度。

有没有办法可以确定字体何时加载 JavaScript。我正在使用 CSS 来加载字体。

I need to measure the navigation of my site to determine the space available for a feature I am building. I recently added a custom font...

The trouble is that I measure the navigation before the new font is loaded. The new font then loads altering the width of the navigation. I am then left with an incorrect width.

Is there a way I can determine when the font has loaded with JavaScript. I am using CSS to load the font.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

—━☆沉默づ 2024-12-26 02:56:35

我假设您在运行 jquery 之前正在等待 $(document).load ?这只是等待 DOM 变得可访问。如果您想等到整个网页(和关联的文件)准备好,请使用 $(window).load:

$(window).bind("load", function() {
       //nav resize code here
});

我不会将整个代码包装在其中,只包装依赖于字体的部分。

I assume you are waiting on $(document).load before running your jquery? This just waits for the DOM to become accessible. If you want to wait until the entire webpage (and associated files) are ready, use $(window).load:

$(window).bind("load", function() {
       //nav resize code here
});

I wouldn't wrap your entire code in this, just the part that is dependent on the fonts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文