2016-01-10 47 views
4

我想在演示文稿中設置頁眉和頁腳。我用下面的問題爲出發點:https://github.com/hakimel/reveal.js/issues/806http://www.ciges.net/revealjs_demo/#/設置頁眉和頁腳reveal.js演示文稿

我目前的實施提供了以下的輸出: enter image description here

現在據我瞭解有通過reveal.js默認使用fixed size for the presentation具有960像素的寬度和700px的高度。這個尺寸對我來說完全沒問題。但是,我希望頁眉和頁腳不要在此窗口中修復。他們需要適應實際的屏幕尺寸。也就是說,我希望左側標題與屏幕的左上角對齊。同樣對於其他頁眉和頁腳,也請參閱圖像。我怎樣才能做到這一點?目前看來,我的頁眉和頁腳在默認窗口(960x700)內是固定的。

我使用下面的代碼(的index.html)與reveal.js 3.2.0

<!doctype html> 
<html lang="en"> 

    <head> 
     <meta charset="utf-8"> 

     <title>reveal.js – The HTML Presentation Framework</title> 

     <meta name="description" content="A framework for easily creating beautiful presentations using HTML"> 
     <meta name="author" content="Hakim El Hattab"> 

     <meta name="apple-mobile-web-app-capable" content="yes"> 
     <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> 

     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"> 

     <link rel="stylesheet" href="css/reveal.css"> 
     <link rel="stylesheet" href="css/theme/simple.css" id="theme"> 

     <!-- Code syntax highlighting --> 
     <link rel="stylesheet" href="lib/css/zenburn.css"> 

     <!-- Printing and PDF exports --> 
     <script> 
      var link = document.createElement('link'); 
      link.rel = 'stylesheet'; 
      link.type = 'text/css'; 
      link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css'; 
      document.getElementsByTagName('head')[0].appendChild(link); 
     </script> 

     <!--[if lt IE 9]> 
     <script src="lib/js/html5shiv.js"></script> 
     <![endif]--> 

     <style type="text/css"> 
      .reveal div.header-left { 
       position: absolute; 
       top: 0; 
       left: 0; 
       padding: 0; 
       margin: 0; 
      } 
      .reveal div.header-right { 
       position: absolute; 
       top: 0; 
       right: 0; 
       padding: 0; 
       margin: 0; 
      } 
      .reveal div.footer-left { 
       position: absolute; 
       bottom: 0; 
       left: 0; 
       padding: 0; 
       margin: 0; 
      } 
      .reveal div.footer-right { 
       position: absolute; 
       bottom: 0; 
       right: 0; 
       padding: 0; 
       margin: 0; 
      } 
     </style> 

    </head> 

    <body> 

     <div id="hidden" style="display:none;"> 
      <div id="header"> 
       <div class="header-left">test header left</div> 
       <div class="header-right">test header right</div> 
       <div class="footer-left">test footer left</div> 
       <div class="footer-right">test footer right</div> 
      </div> 
     </div> 

     <div class="reveal"> 

      <!-- Any section element inside of this container is displayed as a slide --> 
      <div class="slides"> 
       <section> 
        <h1>Reveal.js</h1> 
        <h3>The HTML Presentation Framework</h3> 
        <p> 
         <small>Created by $x^2$ <a href="http://hakim.se">Hakim El Hattab</a>/<a href="http://twitter.com/hakimel">@hakimel</a></small> 
        </p> 
       </section> 

       <section> 
        <h2>Hello There</h2> 
        <p> 
         reveal.js enables you to create beautiful interactive slide decks using HTML. This presentation will show you examples of what it can do. 
        </p> 
       </section> 

       <!-- Example of nested vertical slides --> 
       <section> 
        <section> 
         <h2>Vertical Slides</h2> 
         <p>Slides can be nested inside of each other.</p> 
         <p>Use the <em>Space</em> key to navigate through all slides.</p> 
         <br> 
         <a href="#" class="navigate-down"> 
          <img width="178" height="238" data-src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Down arrow"> 
         </a> 
        </section> 
        <section> 
         <h2>Basement Level 1</h2> 
         <p>Nested slides are useful for adding additional detail underneath a high level horizontal slide.</p> 
        </section> 
        <section> 
         <h2>Basement Level 2</h2> 
         <p>That's it, time to go back up.</p> 
         <br> 
         <a href="#/2"> 
          <img width="178" height="238" data-src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Up arrow" style="transform: rotate(180deg); -webkit-transform: rotate(180deg);"> 
         </a> 
        </section> 
       </section> 

      </div> 

     </div> 

     <script src="lib/js/head.min.js"></script> 
     <script src="js/reveal.js"></script> 

     <script> 

      // Full list of configuration options available at: 
      // https://github.com/hakimel/reveal.js#configuration 
      Reveal.initialize({ 
       controls: false, 
       progress: true, 
       slideNumber: true, 
       history: true, 
       center: false, 
       transition: 'slide', // none/fade/slide/convex/concave/zoom 
       math: { 
        mathjax: 'https://cdn.mathjax.org/mathjax/latest/MathJax.js', 
        config: 'TeX-AMS_HTML-full' // See http://docs.mathjax.org/en/latest/config-files.html 
       }, 
       // Optional reveal.js plugins 
       dependencies: [ 
        { 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', condition: function() { return !!document.querySelector('[data-markdown]'); } }, 
        { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, 
        { src: 'plugin/zoom-js/zoom.js', async: true }, 
        { src: 'plugin/notes/notes.js', async: true }, 
        { src: 'plugin/math/math.js', async: true } 
       ] 
      }); 

     </script> 

     <script src="//code.jquery.com/jquery-2.2.0.min.js"></script> 

     <script type="text/javascript"> 
      var header = $('#header').html(); 
      if (window.location.search.match(/print-pdf/gi)) { 
       $('.slides > section').prepend(header); 
      } else { 
       $('.slides').prepend(header); 
      } 
     </script> 

    </body> 

</html> 
+0

演示網址上沒有標題問題。如果您發現解決方案只是回答您的問題並接受它。幫助其他成員。解決方案必須將滑塊外部的頁眉和頁腳放在絕對位置。 –

回答

0

插入頁眉/頁腳元素帶入div.reveal元件代替.slides滑動元件。

插入頁眉/頁腳元素的DOM樹中的位置會影響應用哪個CSS,從而影響其定位。

  • $('.slides').prepend(header)添加slides <DIV>內的元素。這些元素將被固定爲默認(960x700)窗口,因爲這是slides <div>的大小。
  • $('div.reveal').append(header)添加reveal <div>中的元素。元素將固定在屏幕上,因爲reveal <div>的大小設置爲佔用整個瀏覽器視圖端口。

注意這不適合打印/ PDF版本的工作...我還在試圖找出那一個了...

7

這裏a slightly more complicated answer,也可用於PDF格式-export印刷版:

的元素添加到slide-background <DIV>(而不是sectionslides,或reveal)。這<div>是動態生成的,所以我們必須等待Reveal.js ready事件。打印時會稍稍延遲,然後不必要的頁眉和頁腳動畫就會移動到位,但所有頁眉/頁腳都會根據需要呈現在PDF中。

僞代碼:

  1. 樣式頁眉/頁腳<DIV>從而期望它們定位。
  2. 創建隱藏頁眉/頁腳<格>
  3. 在Reveal.js ready事件,複製頁眉/頁腳<DIV>到每個.slide-background <格>

代碼:這可以複製粘貼到reveal.js文件的末尾(在結束< /正文>標籤之前):

<style type="text/css"> 
    /* 1. Style header/footer <div> so they are positioned as desired. */ 
    #header-left { 
     position: absolute; 
     top: 0%; 
     left: 0%; 
    } 
    #header-right { 
     position: absolute; 
     top: 0%; 
     right: 0%; 
    } 
    #footer-left { 
     position: absolute; 
     bottom: 0%; 
     left: 0%; 
    } 
</style> 

<!-- 2. Create hidden header/footer <div> --> 
<div id="hidden" style="display:none;"> 
    <div id="header"> 
     <div id="header-left">HEADER-LEFT</div> 
     <div id="header-right">HEADER-RIGHT</div> 
     <div id="footer-left">FOOTER-LEFT</div> 
    </div> 
</div> 

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 
<script type="text/javascript"> 
    // 3. On Reveal.js ready event, copy header/footer <div> into each `.slide-background` <div> 
    var header = $('#header').html(); 
    if (window.location.search.match(/print-pdf/gi)) { 
     Reveal.addEventListener('ready', function(event) { 
      $('.slide-background').append(header); 
     }); 
    } 
    else { 
     $('div.reveal').append(header); 
    } 
</script>