描述:
使用EPUB.js实现电子书功能
参考:
EPUB.js: https://github.com/futurepress/epub.js
问题:
提前生成的epub文件,使用EPUB.js渲染到dom后,就可以全部阅读了,但是需要是用户只能阅读指定章节,达到一定条件后才能全部阅读.请问,如何限制用户可以阅读的章节?
//注册epub book this.book = window.ePub(`../../../static/ebooks/${bookName}.epub`, { restore: true }) //监听 章节渲染 this.book.on('renderer:chapterDisplayed',() => { this.chapterPageNum = 1 }) //点击下一页 goToNextPage () { if (this.chapterPageNum >= this.book.currentChapter.pages) { this.showToast('精彩内容,敬请期待~') } else { this.chapterPageNum += 1 this.book.nextPage() } }
在epubBook.currentChapter中可以获取当前章节的总共多少页,当页数>=总页数时,不允许跳转下一页即可.