jQuery - 检测自定义字体何时加载?
我需要测量网站的导航以确定可用于我正在构建的功能的空间。我最近添加了自定义字体...
问题是我在加载新字体之前测量了导航。然后加载新字体并改变导航的宽度。然后我留下了不正确的宽度。
有没有办法可以确定字体何时加载 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您在运行 jquery 之前正在等待 $(document).load ?这只是等待 DOM 变得可访问。如果您想等到整个网页(和关联的文件)准备好,请使用 $(window).load:
我不会将整个代码包装在其中,只包装依赖于字体的部分。
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:
I wouldn't wrap your entire code in this, just the part that is dependent on the fonts.