jquery 在@font-face 上抛出错误

标签 jquery css font-face

我正在本地处理一个元素,并且在我的@fontface 上收到一个 jquery 错误。

这是我的错误:

jquery-1.11.0.min.js:2 GET http://localhost:9000/ostrich-regular-webfont.woff2

这是我的工作目录:

src
| -img
| -scripts
| -styles
     -main.css
     -fonts
          -font files are here
| -index

我的@font-face:

@font-face {
font-family: 'ostrich_sansmedium';
src: url('ostrich-regular-webfont.eot');
src: url('ostrich-regular-webfont.eot?#iefix') format('embedded-opentype'),
     url('ostrich-regular-webfont.woff2') format('woff2'),
     url('ostrich-regular-webfont.woff') format('woff'),
     url('ostrich-regular-webfont.ttf') format('truetype'),
     url('ostrich-regular-webfont.svg#ostrich_sansmedium') format('svg');
font-weight: normal;
font-style: normal;

我尝试了 url 的不同变体,包括:

 url('fonts/ostrich-regular-webfont.svg#ostrich_sansmedium'),
 url('styles/fonts/ostrich-regular-webfont.svg#ostrich_sansmedium') 

等等

有人有什么建议吗?任何建议表示赞赏!

最佳答案

当 IIS 未正确配置时,我经常看到字体文件出现此类错误。如果您确定文件在那里(您尝试修复它的路径看起来是正确的),那么可能是 IIS 不确定如何提供这些文件(即它们将 404因为用户无法下载它们,因为 IIS 不会为它们提供服务)。在您的 web.config 文件中,添加以下内容:

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />

很明显,mimeMap 条目将位于任何已存在的父节点中,您必须关闭它们。我刚刚将其包括在内,以帮助您了解它的去向。

关于jquery 在@font-face 上抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318113/

相关文章:

jquery - 列在 wordpress 中具有 100% 的高度

javascript - jqGrid (v4.1.2) 树网格的排序不适用于邻接模型

html - Bootstrap - 如何在一个 div 行中以相等的宽度容纳 7 列并且没有浪费

fonts - @font-face 是如何工作的?

ios - 某些元素在 OS X 中不显示带有字体的文本

css - CSS3 中的@font-face 错误

javascript - 如何清除/清空 dojo 小部件

javascript - jquery自定义事件困惑

html - 将鼠标悬停在一个词上并显示相关图像

jquery - 应用 CSS3 动画时 Chrome 屏幕闪烁(仅第一次)