font.html 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>RequireJS + WebFont Loader</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <style>
  8. body{font-family:sans-serif}
  9. .h3{font-size:1.2em}
  10. .info{background-color:#cfc; border:2px solid #ada; padding:10px 20px; margin:2em 0}
  11. .wf-loading .f-1,
  12. .wf-loading .f-2,
  13. .wf-loading .f-3 {
  14. /* avoid FOUC */
  15. visibility:hidden;
  16. }
  17. .f-1{font-family:"Tangerine"}
  18. .f-2{font-family:"Cantarell"}
  19. .f-3{font-family:"Yanone Kaffeesatz"}
  20. </style>
  21. </head>
  22. <script>
  23. // add .wf-loading class to avoid FOUC
  24. // use JS to add class to avoid hidding content if JS isn't available
  25. document.documentElement.className += ' wf-loading';
  26. </script>
  27. <body>
  28. <div id="wrapper">
  29. <h1>RequireJS + WebFont Loader</h1>
  30. <div class="info">
  31. <p>
  32. Example of how to load webfonts using the <a href="https://code.google.com/apis/webfonts/docs/webfont_loader.html">Google WebFont Loader API</a>.
  33. </p>
  34. <h2 class="h3">Syntax</h2>
  35. <p>
  36. <code>font!google,families:[Tangerine,Cantarell]</code>
  37. </p>
  38. <p>
  39. You can load fonts from multiple vendors by splitting them with &quot;|&quot;.
  40. </p>
  41. <p>
  42. <code>font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]|typekit,id:123|monotype,projectId:555</code>
  43. </p>
  44. <p>
  45. Check the <a href="https://code.google.com/apis/webfonts/docs/webfont_loader.html">WebFont Loader API documentation</a> for available options.
  46. </p>
  47. </div>
  48. <div id="sample">
  49. <h2 class="f-1">Lorem Ipsum dolor</h2>
  50. <p class="f-2">
  51. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  52. </p>
  53. <p class="f-3">
  54. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  55. </p>
  56. </div>
  57. </div>
  58. <script src="../lib/require.js"></script>
  59. <script>
  60. require({
  61. waitSeconds : 15, //make sure it is enough to load all scripts
  62. paths : {
  63. //alias to plugins
  64. async : '../src/async',
  65. goog : '../src/goog',
  66. font : '../src/font',
  67. propertyParser : '../src/propertyParser'
  68. }
  69. });
  70. require(['font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]'], function(){
  71. //fonts are loaded
  72. var ready = document.createElement('div');
  73. ready.className = 'f-1';
  74. ready.innerHTML = 'All fonts loaded!';
  75. ready.style.fontSize = '34px';
  76. document.getElementById('sample').appendChild(ready);
  77. });
  78. </script>
  79. </body>
  80. </html>