javascript – 设置页眉和页脚reveal.js演示文稿

前端之家收集整理的这篇文章主要介绍了javascript – 设置页眉和页脚reveal.js演示文稿前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在演示文稿中设置页眉和页脚.我使用以下问题作为起点: https://github.com/hakimel/reveal.js/issues/806http://www.ciges.net/revealjs_demo/#/

我当前的实现提供了以下输出

据我所知,reveal.js默认使用fixed size for the presentation,宽度为960px,高度为700px.这个尺寸对我来说完全没问题.但是,我希望不在此窗口中修复页眉和页脚.他们需要适应实际的屏幕尺寸.也就是说,我希望左标题与屏幕的左上角对齐.同样对于其他页眉和页脚,另请参见图像.我怎样才能做到这一点?目前看来我的页眉和页脚是固定在默认窗口(960×700).

我在reveal.js 3.2.0中使用以下代码(index.html)

  1. <!doctype html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <Meta charset="utf-8">
  6.  
  7. <title>reveal.js – The HTML Presentation Framework</title>
  8.  
  9. <Meta name="description" content="A framework for easily creating beautiful presentations using HTML">
  10. <Meta name="author" content="Hakim El Hattab">
  11.  
  12. <Meta name="apple-mobile-web-app-capable" content="yes">
  13. <Meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  14.  
  15. <Meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui">
  16.  
  17. <link rel="stylesheet" href="css/reveal.css">
  18. <link rel="stylesheet" href="css/theme/simple.css" id="theme">
  19.  
  20. <!-- Code Syntax highlighting -->
  21. <link rel="stylesheet" href="lib/css/zenburn.css">
  22.  
  23. <!-- Printing and PDF exports -->
  24. <script>
  25. var link = document.createElement( 'link' );
  26. link.rel = 'stylesheet';
  27. link.type = 'text/css';
  28. link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
  29. document.getElementsByTagName( 'head' )[0].appendChild( link );
  30. </script>
  31.  
  32. <!--[if lt IE 9]>
  33. <script src="lib/js/html5shiv.js"></script>
  34. <![endif]-->
  35.  
  36. <style type="text/css">
  37. .reveal div.header-left {
  38. position: absolute;
  39. top: 0;
  40. left: 0;
  41. padding: 0;
  42. margin: 0;
  43. }
  44. .reveal div.header-right {
  45. position: absolute;
  46. top: 0;
  47. right: 0;
  48. padding: 0;
  49. margin: 0;
  50. }
  51. .reveal div.footer-left {
  52. position: absolute;
  53. bottom: 0;
  54. left: 0;
  55. padding: 0;
  56. margin: 0;
  57. }
  58. .reveal div.footer-right {
  59. position: absolute;
  60. bottom: 0;
  61. right: 0;
  62. padding: 0;
  63. margin: 0;
  64. }
  65. </style>
  66.  
  67. </head>
  68.  
  69. <body>
  70.  
  71. <div id="hidden" style="display:none;">
  72. <div id="header">
  73. <div class="header-left">test header left</div>
  74. <div class="header-right">test header right</div>
  75. <div class="footer-left">test footer left</div>
  76. <div class="footer-right">test footer right</div>
  77. </div>
  78. </div>
  79.  
  80. <div class="reveal">
  81.  
  82. <!-- Any section element inside of this container is displayed as a slide -->
  83. <div class="slides">
  84. <section>
  85. <h1>Reveal.js</h1>
  86. <h3>The HTML Presentation Framework</h3>
  87. <p>
  88. <small>Created by $x^2$<a href="http://hakim.se">Hakim El Hattab</a> / <a href="http://twitter.com/hakimel">@hakimel</a></small>
  89. </p>
  90. </section>
  91.  
  92. <section>
  93. <h2>Hello There</h2>
  94. <p>
  95. reveal.js enables you to create beautiful interactive slide decks using HTML. This presentation will show you examples of what it can do.
  96. </p>
  97. </section>
  98.  
  99. <!-- Example of nested vertical slides -->
  100. <section>
  101. <section>
  102. <h2>Vertical Slides</h2>
  103. <p>Slides can be nested inside of each other.</p>
  104. <p>Use the <em>Space</em> key to navigate through all slides.</p>
  105. <br>
  106. <a href="#" class="navigate-down">
  107. <img width="178" height="238" src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Down arrow">
  108. </a>
  109. </section>
  110. <section>
  111. <h2>Basement Level 1</h2>
  112. <p>Nested slides are useful for adding additional detail underneath a high level horizontal slide.</p>
  113. </section>
  114. <section>
  115. <h2>Basement Level 2</h2>
  116. <p>That's it,time to go back up.</p>
  117. <br>
  118. <a href="#/2">
  119. <img width="178" height="238" src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Up arrow" style="transform: rotate(180deg); -webkit-transform: rotate(180deg);">
  120. </a>
  121. </section>
  122. </section>
  123.  
  124. </div>
  125.  
  126. </div>
  127.  
  128. <script src="lib/js/head.min.js"></script>
  129. <script src="js/reveal.js"></script>
  130.  
  131. <script>
  132.  
  133. // Full list of configuration options available at:
  134. // https://github.com/hakimel/reveal.js#configuration
  135. Reveal.initialize({
  136. controls: false,progress: true,slideNumber: true,history: true,center: false,transition: 'slide',// none/fade/slide/convex/concave/zoom
  137. math: {
  138. mathjax: 'https://cdn.mathjax.org/mathjax/latest/MathJax.js',config: 'TeX-AMS_HTML-full' // See http://docs.mathjax.org/en/latest/config-files.html
  139. },// Optional reveal.js plugins
  140. dependencies: [
  141. { src: 'lib/js/classList.js',condition: function() { return !document.body.classList; } },{ src: 'plugin/markdown/marked.js',condition: function() { return !!document.querySelector( '[data-markdown]' ); } },{ src: 'plugin/markdown/markdown.js',{ src: 'plugin/highlight/highlight.js',async: true,callback: function() { hljs.initHighlightingOnLoad(); } },{ src: 'plugin/zoom-js/zoom.js',async: true },{ src: 'plugin/notes/notes.js',{ src: 'plugin/math/math.js',async: true }
  142. ]
  143. });
  144.  
  145. </script>
  146.  
  147. <script src="//code.jquery.com/jquery-2.2.0.min.js"></script>
  148.  
  149. <script type="text/javascript">
  150. var header = $('#header').html();
  151. if ( window.location.search.match( /print-pdf/gi ) ) {
  152. $('.slides > section').prepend(header);
  153. } else {
  154. $('.slides').prepend(header);
  155. }
  156. </script>
  157.  
  158. </body>
  159.  
  160. </html>

解决方法

这是 a slightly more complicated answer,也适用于pdf-export打印版本:

将元素添加幻灯片背景< div> (而不是部分,幻灯片或揭示).这个< div>是动态生成的,所以我们必须等待Reveal.js ready事件.打印时会有轻微的延迟,接着是页眉和页脚移动到位的不必要的动画,但所有页眉/页脚都会根据需要在PDF中呈现.

代码

>样式页眉/页脚< div>所以他们按照需要定位.
>创建隐藏的页眉/页脚< div>
>在Reveal.js就绪事件中,复制页眉/页脚< div>进入每个.slide-background< div>

代码:这可以复制粘贴到reveal.js文件的末尾(在结束< / body>标记之前):

  1. <style type="text/css">
  2. /* 1. Style header/footer <div> so they are positioned as desired. */
  3. #header-left {
  4. position: absolute;
  5. top: 0%;
  6. left: 0%;
  7. }
  8. #header-right {
  9. position: absolute;
  10. top: 0%;
  11. right: 0%;
  12. }
  13. #footer-left {
  14. position: absolute;
  15. bottom: 0%;
  16. left: 0%;
  17. }
  18. </style>
  19.  
  20. <!-- 2. Create hidden header/footer <div> -->
  21. <div id="hidden" style="display:none;">
  22. <div id="header">
  23. <div id="header-left">HEADER-LEFT</div>
  24. <div id="header-right">HEADER-RIGHT</div>
  25. <div id="footer-left">FOOTER-LEFT</div>
  26. </div>
  27. </div>
  28.  
  29. <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
  30. <script type="text/javascript">
  31. // 3. On Reveal.js ready event,copy header/footer <div> into each `.slide-background` <div>
  32. var header = $('#header').html();
  33. if ( window.location.search.match( /print-pdf/gi ) ) {
  34. Reveal.addEventListener( 'ready',function( event ) {
  35. $('.slide-background').append(header);
  36. });
  37. }
  38. else {
  39. $('div.reveal').append(header);
  40. }
  41. </script>

猜你在找的JavaScript相关文章