你如何设置requirejs和Google Web Fonts
How do you set up requirejs and Google Web Fonts?
我正在使用requirejs插件,并尝试将一些谷歌网络字体加载到我的脚本中使用。我发现有几个例子或多或少地模仿了那个 github 页面上的例子。
示例:使用 require.js 字体插件加载 Google 网络字体
我还阅读了字体插件的源代码并在我的例子中尝试了这个,但它仍然不起作用。
Line 28:
example: font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]
这是我到目前为止的代码。
requirejs.config({
font: '../bower_components/requirejs-plugins/src/font',
propertyParser: '../bower_components/requirejs-plugins/src/propertyParser'
});
define(['font!google,families:[Yanone Kaffeesatz:700]'], function(Font) {
console.log(Font);
});
这是加载时在控制台中触发的错误。
Uncaught ReferenceError: WebFont is not defined
这发生在字体的第 38 行.js
这是怎么回事?我觉得我错过了某种配置或其他东西。如您所见,我正在使用脚本建议的确切示例导入。有没有实际使用的例子?
经过一番调查,我发现实际上由于进行了代码更改,https://github.com/millermedeiros/requirejs-plugins/issues/71 中已经列出了一个错误。该错误已在 16 天前列出,并且仍然处于打开状态,对您没有帮助。与此同时,您应该能够对您的插件版本进行以下更改,这些更改应该将您绑定到官方 bower 存储库之前。
在 bower_components/requirejs-plugins/src/font.js 第 37 行将其从:
req([(document.location.protocol === 'https:'? 'https' : 'http') +'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'], function(){
自:
req([(document.location.protocol === 'https:'? 'https' : 'http') +'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'], function(WebFont){
那个"WebFont"是被投诉的那个。
相关文章:
- 如何在Google柱状图中动态添加行/列
- Google/html5语音识别JavaScript SDK Chrome网络工具包SpeechRecognition
- 使用Google Visualization动态调用构造函数
- Firebase2(Firebase.google.com)推送通知-从外部管理
- 是否可以控制获取哪些Google地图脚本(JavaScript API)
- 以可优化的方式使用requirejs加载模板
- RequireJS向模块传递配置总是返回undefined
- 通过命令行/批处理文件打开页面时,将javascript代码注入Google Chrome
- Google Adsense多次加载脚本
- 单击超链接时,如何使用Google Maps API v3缩放地图
- Google电子表格getValue([cell containing ])不返回制表符
- 实现一个建立在google.com之上的自定义搜索引擎
- 使用Google Maps API向标记添加多个字符
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- 回调函数中传递参数的困难(Google Map API Markers)
- 在Chrome扩展内部输出Google API调用
- 如何使用Google Sheets API+Javascript阅读电子表格
- 如何使用javascript更改google repatcha的大小
- 你如何设置requirejs和Google Web Fonts
- 使用 RequireJS 加载 Google 地图自动完成功能