javascript - 设置页眉和页脚 rev​​eal.js 演示

标签 javascript html css presentation reveal.js

我想在我的演示文稿中设置页眉和页脚。我使用以下问题作为起点:https://github.com/hakimel/reveal.js/issues/806http://www.ciges.net/revealjs_demo/#/

我当前的实现给出了以下输出: enter image description here

据我所知,reveal.js 使用 fixed size for the presentation默认情况下,宽度为 960px,高度为 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>

最佳答案

这里是 a slightly more complicated answer这也适用于 pdf 导出打印版本:

将元素添加到 slide-background

(而不是 sectionslidesreveal).这个
是动态生成的,所以我们必须等待 Reveal.js ready 事件。打印时会有轻微的延迟,随后是页眉和页脚移动到位的不必要的动画,但所有页眉/页脚都按需要呈现在 PDF 中。

伪代码:

  1. 设置页眉/页脚
    的样式,使其按需要放置。
  2. 创建隐藏的页眉/页脚
  3. 在 Reveal.js 就绪事件中,将页眉/页脚
    复制到每个 .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>

关于javascript - 设置页眉和页脚 rev​​eal.js 演示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34706859/

相关文章:

javascript - 如何获得一个按钮来填充移动 View 中页脚的整个宽度?

javascript - 如何在表单提交过程中调用$.get?

javascript - jQuery或JS,让元素在底部离开屏幕并在顶部进入

php - 如何防止我的“LIKE”按钮在客户端和服务器端发送垃圾邮件

javascript - 使用具有相同功能的多个事件

php - 将两个查询的值匹配到同一个表中

html - svg inside scroll div 有一个底部排水沟

html - 居中和缩放(响应式!)div-wrapper,里面有几个 div

javascript - 单击搜索输入时,Android 键盘出现和消失

javascript - ThreeJS高亮/投影仪