【问题标题】:Working on epub using CSS columns, regarding pagination使用 CSS 列在 epub 上工作,关于分页
【发布时间】:2017-11-13 10:22:08
【问题描述】:

我正在研究要在浏览器中读取的 epub 文件格式。 使用 CSS 列 我可以根据窗口高度将内容分成几列(几页)。 使用 Next/Previous 按钮,我会做 translateX

我的问题是关于分页。我如何确定:

  • 浏览器中特定电子书的总列数,我将用它作为总页数。

  • 在视口中可见的当前列,我将其用作当前页面位置。

如果 CSS 列不适合这种情况,您可以向我建议任何更好的方法。

编辑:我将 epub 呈现为可重排的内容(动态分页)。

谢谢!

【问题讨论】:

  • 这是一个有趣的方法,但我认为你会遇到这些 CSS 列的问题。我不知道如何获取总列数或当前可见列。你可以看看 Readium,或者 Edge 最新版本的 EPUB 阅读支持,看看他们是怎么做的,但我认为基本思想是在一个垂直区域渲染整本书,然后调整哪个部分您在页面上显示的内容。
  • 我不了解 Edge 浏览器,但对于 Readium.. 据我所见,他们的应用程序中没有分页或百分比读取功能 :)
  • Readium 绝对有分页功能。
  • 检查这里github.com/readium/readium-js-viewer/issues/319我会更新问题。

标签: javascript html css pagination epub


【解决方案1】:

更好的方法是生成您自己的列。

查看我的jsfiddle demo,它使用lib_columns.jsjquery.jsjquery.easyPaginate.js

有关easyPaginate.js 的更多信息,请参阅website

有关 lib_columns.js 的更多信息,请参阅website

CSS

<style type="text/css">
html, body { overflow: hidden; height: 100%; }

/* Hide the source containers, by visual only. */
#divSizer, #content {
    visibility: hidden;
    position: absolute;
    left: -9999px;
}

/* E-book */
.ebook-container {
    position: relative;
    background: #CCC;
}
#ebook {
    /*width: 300px; (generated by JavaScript) */
    /*height: 500px; (generated by JavaScript) */
    margin: 0 auto;
    border: 4px dashed red;
    /*overflow: auto; (Provide scrollbar) */
}

/* Pagination Menu */
.ebook-container .easyPaginateNav {
    position: absolute;
    bottom: -2em;
    width: 100% !important;
    text-align: center;
}
.ebook-container .easyPaginateNav a { padding: 5px; }
.ebook-container .easyPaginateNav a.current { font-weight: bold; }

/* Show only the current page in pagination, hide the rest. */
.ebook-container .easyPaginateNav a.page         { display: none; }
.ebook-container .easyPaginateNav a.page.current { display: inline; }

/* Text-size Menu */
.ebook-container .textSizeNav {
    position: absolute;
    bottom: -70px;
    width: 100%;
    text-align: center;
}
</style>

HTML

<body style="font-size: 1.4em;">
    <div id="divSizer"></div>

    <div id="content">
        <h2>7.1 Introduction to media types</h2>

        <p>One of the most important features of style sheets is that they
        specify how a document is to be presented on different media: on the
        screen, on paper, with a speech synthesizer, with a braille device,
        etc.</p>

        <h3>Features of Style Sheets</h3>

        <p>Certain CSS properties are only designed for certain media (e.g.,
        the 'cue-before' property for aural user agents).
        On occasion, however, style sheets for different
        media types may share a property, but require different values for
        that property. For example, the 'font-size' property is useful both
        for screen and print media. However, the two media are different
        enough to require different values for the common property; a document
        will typically need a larger font on a computer screen than on paper.
        Experience also shows that sans-serif fonts are easier to read on
        screen, while fonts with serifs are easier to read on paper.  For
        these reasons, it is necessary to express that a style sheet -- or a
        section of a style sheet -- applies to certain media types.</p>

        <h4>Features of Style Sheets</h4>

        <p>One of the most important features of style sheets is that they
        specify how a document is to be presented on different media: on the
        screen, on paper, with a speech synthesizer, with a braille device,
        etc.</p>

        <p>Experience also shows that sans-serif fonts are easier to read on
        screen, while fonts with serifs are easier to read on paper.  For
        these reasons, it is necessary to express that a style sheet -- or a
        section of a style sheet -- applies to certain media types.</p>

        <h4>Document to be Presented</h4>

        <p>Experience also shows that sans-serif fonts are easier to read on
        screen, while fonts with serifs are easier to read on paper.  However,
        the two media are different enough to require different values for the
        common property</p>

        <p>Certain CSS properties are only designed for certain media (e.g.,
        the 'cue-before' property for aural user agents).
        On occasion, however, style sheets for different.</p>

        <h4>Features of Style Sheets</h4>

        <p>One of the most important features of style sheets is that they
        specify how a document is to be presented on different media: on the
        screen, on paper, with a speech synthesizer, with a braille device,
        etc.</p>

        <p>Experience also shows that sans-serif fonts are easier to read on
        screen, while fonts with serifs are easier to read on paper.  For
        these reasons, it is necessary to express that a style sheet -- or a
        section of a style sheet -- applies to certain media types.</p>

        <h4>Document to be Presented</h4>

        <p>Experience also shows that sans-serif fonts are easier to read on
        screen, while fonts with serifs are easier to read on paper.  However,
        the two media are different enough to require different values for the
        common property</p>

        <p>Certain CSS properties are only designed for certain media (e.g.,
        the 'cue-before' property for aural user agents).
        On occasion, however, style sheets for different.</p>
    </div>

    <div class="ebook-container">
        <div id="ebook"></div>

        <div class="textSizeNav">
            <button id="plustext" class="btn btn-circle" onclick="resizeText(1); $(window).resize();">A<sup><span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span></sup></button>
            <button id="minustext" class="btn btn-circle" onclick="resizeText(-1); $(window).resize();"><small>A</small><sup><span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span></sup></button>
        </div>
    </div>

    <script src="https://cdn.rawgit.com/dpup/13thparallel.com/master/static/archive/column-script/lib_columns.j"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://st3ph.github.io/jquery.easyPaginate/js/jquery.easyPaginate.js"></script>
    <script src="jquery.easyPaginate.func.my_paginate.js"></script>
    <script src="my_app.js"></script>
</body>

JAVASCRIPT - jquery.easyPaginate.func.my_paginate.js

<!-- jquery.easyPaginate.func.my_paginate.js -->
<script>
function my_paginate(book_selector, content_selector, params)
{
    // Override default options.
    params = $.extend({
        pageWidth:       300,
        pageHeight:      500,
        earlyCutOff:     0,
        paginateElement: 'div',
        elementsPerPage: 1,
        effect:          'default', // Choose: 'fade', 'slide', or 'climb'
        prevButtonText: '<',
        firstButtonText: '<<',
        nextButtonText: '>',
        lastButtonText: '>>'
    }, params);

    // If content container is empty, then break.
    var content = $(content_selector);
    if (content.length == 0) return;

    // Reset easyPaginate:
    // - Check if pagination already exists.
    // - Remove pagination, and clear the e-book container.
    var sel = '.easyPaginateNav';
    var pagination = $(book_selector).parent().children(sel);
    if (pagination.length > 0) {
        pagination.first().remove();
        $(book_selector).html('');
    }

    // Generate pages. (splits the content)
    // Note: All pages will have:
    // - class="page"
    // - data-page-num="*"
    var cols = Columns.splitText(
        content.html(),
        params.pageWidth,
        (params.pageHeight - params.earlyCutOff) // Sometimes too long.
    );
    for (var i = 0; i < cols.length; i ++)
    {
        $(book_selector).append(
            '<' + params.paginateElement +
            ' class="page"' +
            ' data-page-num="' + (i + 1) + '"' +
            '>' +
            cols[i] +
            '</' + params.paginateElement + '>'
        );
    }

    // Prepare the e-book container.
    var book = $(book_selector);
    book.css('width', params.pageWidth + 'px');
    book.css('height', params.pageHeight + 'px');

    // Generate/render E-book.
    book.easyPaginate({
        paginateElement: params.paginateElement,
        elementsPerPage: params.elementsPerPage,
        effect: params.effect,
        prevButtonText: params.prevButtonText,
        firstButtonText: params.firstButtonText,
        nextButtonText: params.nextButtonText,
        lastButtonText: params.lastButtonText
    });
}
</script>

JAVASCRIPT - my_app.js

<!-- my_app.js -->
<script>
// When document is ready.
$(function() {
    // When the screen size/dimensions changes:
    $(window).on("resize", function() {
        // Current screen size.
        var width = $(window).width() - 150; // 150px gutter.
        var height = $(window).height() - 125; // 125px gutter.

        // Render e-book.
        my_paginate('#ebook', '#content', {
            pageWidth: width,
            pageHeight: height,
            prevButtonText: '<span class="glyphicon glyphicon-step-backward" aria-hidden="true"></span>',
            firstButtonText: '<span class="glyphicon glyphicon-fast-backward" aria-hidden="true"></span>',
            nextButtonText: '<span class="glyphicon glyphicon-step-forward" aria-hidden="true"></span>',
            lastButtonText: '<span class="glyphicon glyphicon-fast-forward" aria-hidden="true"></span>',
            earlyCutOff: 50
        });
    }).resize(); // Force trigger a resize event.
});
</script>

JAVASCRIPT - 额外

<script>
function resizeText(multiplier) {
    if (document.body.style.fontSize == "") {
        document.body.style.fontSize = "1.0em";
    }
    document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
}
</script>

评论

使用 CSS 列(通过“columns:”属性)会很困难,因为这些列是由 CSS 而不是 HTML 生成的。

使用 HTML(标记),我们在 DOM 中拥有列,因此可以更好地与它们交互和操作。

然后您可以使用 JavaScript 库(例如 jQuery)与您的列进行交互和操作。

【讨论】:

  • 谢谢!但我特别在寻找具有 manipulation example 以获取页码的答案。使用 html 表格或 css flexbox。
  • 出于教育目的,这个答案在 Stackoverflow 中会很有用。
  • Flexbox 无济于事,因为它无法将内容从一个盒子流入另一个盒子。
  • @rnk 我现在提供了一个演示。
  • @RyanBriscall 非常感谢!我检查了演示,它看起来很棒。我需要一些时间来阅读代码。一旦我这样做了,我会回来的。
猜你喜欢
  • 2014-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
  • 2014-03-17
相关资源
最近更新 更多