谷歌api

Google recently debuted a new web service called the Font API.  Google's Font API provides developers a means by which they may quickly and painlessly add custom fonts to their website.  Let's take a quick look at the ways by which the Google Font API can be used.

Google最近推出了一项名为Font API的新网络服务。 Google的Font API为开发人员提供了一种方法,使他们可以快速,轻松地向其网站添加自定义字体。 让我们快速浏览一下Google Font API的使用方式。

View Demo观看演示

字体请求格式 (Font Request Format)

Many of the fonts within Google's font archive are available not only in standard format but also in Italic, Bold, and Italic Bold.  The format for requesting a given font variant is:

Google字体档案库中的许多字体不仅可以使用标准格式,还可以使用Italic,Bold和Italic Bold。 请求给定字体变体的格式为:


{font}:{variant1},{variant2}

Here are a few examples of requesting each variant:

以下是请求每个变体的一些示例:


Cantarell
Cantarell:bold
Cantarell:italic
Cantarell:bolditalic

Now let's see how we can include special fonts in our page and use these them.

现在,让我们看看如何在页面中包含特殊字体并使用它们。

CSS样式表方法 (The CSS Stylesheet Method)


<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Cantarell" />

The stylesheet gets included into the page like any other stylesheet would be.  A query string with a family parameter is appended to the stylesheet's URL containing the font(s) to be loaded.  Multiple fonts can be requested with the use of the "|" (pipe) character.  A few examples:

样式表会像其他样式表一样包含在页面中。 具有Family参数的查询字符串将附加到样式表的URL中,该URL包含要加载的字体。 使用“ |”可以请求多种字体 (管道)字符。 一些例子:


<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Vollkorn" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Vollkorn:bold" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Vollkorn|IM+Fell+Great+Primer" />

Take a moment to examine the stylesheet from Google:

花点时间检查一下Google的样式表:


@font-face {
font-family: 'IM Fell Great Primer';
font-style: normal;
font-weight: normal;
src: local('IM Fell Great Primer'), url('http://themes.googleusercontent.com/font?kit=AL8ALGNthei20f9Cu3e93rvDyRCRMn38Ifm6ee4fjno') format('truetype');
}
@font-face {
font-family: 'Vollkorn';
font-style: normal;
font-weight: normal;
src: local('Vollkorn'), url('http://themes.googleusercontent.com/font?kit=_3YMy3W41J9lZ9YHm0HVxA') format('truetype');
}

The @font-face method of font embedding is Google's chosen method.  Using the font is as simple as using a system font:

字体嵌入的@ font-face方法是Google选择的方法。 使用字体就像使用系统字体一样简单:


.mySpecialFontClass { font-family:'Vollkorn', serif; }

You may also embed the font within the "style" attribute of a given element:

您也可以将字体嵌入给定元素的“ style”属性中:


<p style="font-family:'Vollkorn';">Lorem ipsum....</p>

I t doesn't get more painless than that.

没有比这更轻松的了。

简单JavaScript方法 (The Simple JavaScript Method)

Google also provides a simple JavaScript method for including custom fonts within a page.  This method requires including the JSAPI JavaScript file and a very small snippet of JavaScript:

Google还提供了一种简单JavaScript方法,用于在页面中包含自定义字体。 此方法需要包含JSAPI JavaScript文件和一小段JavaScript代码:


<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('webfont','1');
google.setOnLoadCallback(function() {
WebFont.load({
google: {
families: ['Tangerine','Cantarell']
}
});
});
</script>

Selecting font variants is done with a simple ":" delimiter between the font and the variant:

通过在字体和变体之间使用简单的“:”定界符来选择字体变体:


WebFont.load({
google: {
families: ['Tangerine:bold']
}
});

You may also load multiple fonts within the families array:

您还可以在family数组中加载多种字体:


WebFont.load({
google: {
families: ['Tangerine:bold','Cantarell','Lobster']
}
});

Simple, no?  If it's too simple for you, there's more advanced method.

简单,不是吗? 如果对您来说太简单了,那么还有更高级的方法。

高级JavaScript方法 (The Advanced JavaScript Method)

The advanced JavaScript method employes an async JavaScript method paired with a WebFontConfig object.  The advanced method also adds callbacks for font requests:

高级JavaScript方法采用与WebFontConfig对象配对的异步JavaScript方法。 高级方法还为字体请求添加了回调:


WebFontConfig = {
google: {
families: [ 'Tangerine', 'Cantarell' ]
},
/* Called when all the specified web-font provider modules (google, typekit, and/or custom) have reported that they have started loading fonts. */
loading: function() {
// do something
},
/* Called when each requested web font has started loading. The fontFamily parameter is the name of the font family, and fontDescription represents the style and weight of the font. */
fontloading: function(fontFamily, fontDescription) {
// do something
},
/* Called when each requested web font has finished loading. The fontFamily parameter is the name of the font family, and fontDescription represents the style and weight of the font. */
fontactive: function(fontFamily, fontDescription) {
// do something
},
/* Called if a requested web font failed to load. The fontFamily parameter is the name of the font family, and fontDescription represents the style and weight of the font. */
fontinactive: function(fontFamily, fontDescription) {
// do something
},
/* Called when all of the web fonts have either finished loading or failed to load, as long as at least one loaded successfully. */
active: function() {
// do something
},
/* Called if the browser does not support web fonts or if none of the fonts could be loaded. */
inactive: function() {
// do something
}
};
/* async! */
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();

If you're like me, you loooooooove JavaScript callbacks.  You would use this method if you wanted to "preload" fonts before assigning fonts to specific elements. What's also great about this method is that Google uses "active" and "inactive" CSS class representations on the HTML element to designate what an element's settings should be before and after a font has been loaded:

如果您像我,则可以放松JavaScript回调。 如果要在将字体分配给特定元素之前“预加载”字体,则可以使用此方法。 此方法的优点还在于Google在HTML元素上使用“活动”和“非活动” CSS类表示形式来指定在加载字体之前和之后元素的设置应为:


.wf-inactive p { /* Show paragraphs in serif font until fonts have loaded. */
font-family: serif
}
.wf-active p { /* Show paragraphs in Tangerine when the fonts have loaded. */
font-family: 'Tangerine', serif
}
.wf-inactive h1 { /* Show heading in serif font until fonts have loaded. */
font-family: serif;
font-size: 16px
}
.wf-active h1 { /* Show heading in Cantarell when the fonts have loaded. */
font-family: 'Cantarell', serif;
font-size: 16px
}

Unfortunately you need to add these directives to you stylesheet; I prefer not to.

不幸的是,您需要将这些指令添加到样式表中。 我不想。

View Demo观看演示

What do you think of Google latest JavaScript API?  On one side I see the Font API as extremely useful but the other side of me sees Google trying to grab a stronger hold of the Web;  trying to make websites dependent upon them.  What are your thoughts?

您如何看待Google最新JavaScript API? 一方面,我认为Font API极为有用,但另一方面,我却认为Google试图抢占网络的基础。 试图使网站依赖他们。 你觉得呢?你有没有什么想法?

翻译自: https://davidwalsh.name/google-fonts-api

谷歌api

http://www.taodudu.cc/news/show-4669226.html

相关文章:

  • 谷歌字体下载安装(感觉没有很好用)
  • 读书真的重要吗?(一)
  • 无人机网络的核心技术
  • 【无人机】【2012.09】将无人驾驶飞机系统融入城市环境中的现代警务研究
  • 无人机三维航迹规划
  • 无人机基础知识:多旋翼无人机系统基本组成
  • 无人机调度管理系统平台
  • 更改airsim无人机模型
  • 利用Mavros控制无人机
  • 无人机坐标系定义与转换
  • 无人机与视觉结合项目
  • 无人机测试用例
  • 无人机的路径规划
  • 无人机组装调试教程
  • 小米6鲁大师html5评测,小米6跑分超110万?鲁大师官方:网友PS的图片
  • 鲁大师发布Q1手机性能榜,ROG5幻影夺冠,超过93万分!
  • 小米6鲁大师html5评测,鲁大师曝光小米6跑分:这个分数满意吗?
  • 鲁大师PC最新硬件排行,汇总Q1季度最强PC硬件产品!
  • 鲁大师手机HTML5性能,鲁大师5月新机性能排行:同样是线上手机,跑分相差30万?...
  • 鲁大师测试软件的算法,鲁大师是如何检测内存的?检测内存的方法
  • 鲁大师发布2021年Q1季度报告,哪些手机最强?
  • l5630鲁大师跑分_鲁大师安卓3D引擎更新,跑分测试精准度再升级
  • 鲁大师6月新机流畅榜:HarmonyOS跑分亮相
  • 鲁大师Q3季度手机报告:性能最强、最流畅手机揭晓!
  • 鲁大师2021牛角尖奖最强性能手机揭晓,小米12 Pro拿下大奖
  • 鲁大师发布2021年度手机报告,去年最强的手机一文看完
  • l5630鲁大师跑分_鲁大师跑分详解-内存篇:内存跑分为什么比别人低?分数差在哪?...
  • 计算机评分主硬盘分数低,鲁大师跑分详解-内存篇:内存跑分为什么比别人低?分数差在哪?...
  • 鲁大师12月新机性能榜:跑分116万,小米12 Pro夺冠
  • 肌肉拉伤、劳损

谷歌api_Google字体API相关推荐

  1. 淘宝退款崩溃;马云预言成真;谷歌推新API | 极客头条

    「CSDN 极客头条」,是从 CSDN 网站延伸至官方微信公众号的特别栏目,专注于一天业界事报道.风里雨里,我们将每天为朋友们,播报最新鲜有料的新闻资讯,让所有技术人,时刻紧跟业界潮流. 快讯速知 淘 ...

  2. css 谷歌字体加载,使用谷歌网页字体无限制的添加字体到您的网站

    很长一段时间,网站的开发受到影响,因为他们的资源,他们只能使用少数几种字体.但是,现在谷歌推出新的Web服务"谷歌网页字体".该服务允许您使用不同的字体在您的网站从谷歌的可能性.使 ...

  3. 采用抓包的方式逆向获得谷歌翻译的API

    文章目录 最开始的尝试 2022.12.26 谷歌翻译API相关信息 发送网址 提交的数据 不过不出意外的失败了 实验 去掉参数 去掉Headers 代码 对返回结果进行解析 完整代码 最开始的尝试 ...

  4. Linux Mint 17.1默认使用谷歌Noto字体

    Linux Mint 17.1默认使用谷歌Noto字体 原文地址:http://segfault.linuxmint.com/2014/11/fonts-noto-cjk/ 编译整理:薄荷开源网 还魂 ...

  5. Google Web 字体 API 访谈

    对很多纠结于字体的 Web 设计与开发者而言,昨天有关 Google Font API 的新 闻 着实让他们高兴了一回,这个非常简单实用的 API 包含了一套字体库 和预览工具 ,结合 Google ...

  6. 谷歌离线地图Api附获取教程

    三版离线Api下载链接:https://pan.baidu.com/s/1ei6tyLKTHMIGdDuowqQW6Q 提取码:x1va GoogleMapAPIV3来自: https://www.c ...

  7. python 谷歌地图api_《Python网络编程》学习笔记--使用谷歌地理编码API获取一个JSON文档...

    Foundations of Python Network Programing,Third Edition <python网络编程>,本书中的代码可在Github上搜索fopnp下载 本 ...

  8. 谷歌开放语音识别 API,发力人工智能

    谷歌Next云计算大会今日在美国旧金山召开.谷歌在会上发布了面向开发者的新机器学习平台,并开放语音识别的API(应用程序编程接口).机器学习平台初期将免费提供给开发者.谷歌母公司Alphabet董事长 ...

  9. 谷歌地图JavaScript API第3版 地理编码服务

    地理编码服务 概观 地理编码请求 地理编码响应 地理编码结果 地址组件类型 状态代码 反向地理编码 视口偏置 区码偏置 概观 地理编码地址(如"1600剧场百汇,山景,CA")转换 ...

最新文章

  1. codeforces597c[树状数组+dp]
  2. 这次我让你彻底弄懂 RESTful
  3. Jmeter常见问题(转)
  4. 我的梦想是十年内成为架构师,该怎么办?
  5. linux nc命令用法举例
  6. php数组排序id取得,php专用数组排序类ArraySortUtil用法实例
  7. 晨哥真有料丨为什么越优秀的女生越寡?
  8. Kafka启动报错:Timed out waiting for connection while in state: CONNECTING
  9. stl.find_if用法总结
  10. linux系统命令行方式复制文件
  11. 浅谈最短路径的几个方法(Dijkstra,Bellman-Ford,SPFA,Floyd算法)
  12. linux各个目录作用详解,linux各个目录作用
  13. 高德地图设置中国经纬度范围
  14. jquery进度条组件
  15. ppt科研绘图之通过vba一键导出pdf
  16. python局域网收集数据_Python实现扫描局域网活动ip
  17. ad引脚名字设置_AD软件管脚名称如何放置负信号?
  18. 【无标题】C基础 2
  19. 什么是内网穿透技术?简单实用、永久免费内网穿透工具有哪些?
  20. 模电学习笔记(八)——差分放大器

热门文章

  1. OLED显示文字,字母,数字
  2. Qt开发:Qt Widgets模块——简介
  3. UsbAccessory和UsbDevice的区别
  4. 笔记本电脑使用电池时屏幕不停的更改亮度 - 解决方案
  5. 阿布扎比王储支持区块链在航空业的应用
  6. 『驻外』工作,不是只有非洲
  7. 薅羊毛: 微信小程序开发者可以免费使用验证码短信服务了!
  8. 最近帮朋友写了一个百度竞价关键词快速分词(分组)工具,支持与或逻辑分组,附源码和工具下载链接...
  9. 【RFC7323 高性能的TCP扩展】(翻译)
  10. 魔兽世界服务器显示负载离线,《WOW》服务器负载过高 官方免费转服