美文网首页
epub.js的使用

epub.js的使用

作者: vidou_b552 | 来源:发表于2019-01-20 00:46 被阅读0次

npm安装

npm install epubjs

epub阅读器开发

ePub电子书解析和渲染

生成Book对象
  this.book = new Epub(DOWNLOAD_URL)
通过Book.renderTo生成Rendition对象
  this.rendition = this.book.renderTo('read', {
    width: window.innerWidth,
    height: window.innerHeight,
    method: 'default'
  })
通过Rendtion.display渲染电子书
  this.rendition.display()

ePub电子书翻页

上一页
  function prevPage() {
    if (this.rendition) {
      this.rendition.prev()
    }
  }
下一页
  function nextPage() {
    if (this.rendition) {
      this.rendition.next()
    }
  }

ePub电子书的字号设置和场景切换

设置主题
  function setTheme(index) {
    this.themes.select(this.themeList[index].name)
    this.defaultTheme = index
  }
注册主题
  function registerTheme() {
    this.themeList.forEach(theme => {
      this.themes.register(theme.name, theme.style)
    })
  }
设置字号大小
  function setFontSize(fontSize) {
    this.defaultFontSize = fontSize
    if (this.themes) {
      this.themes.fontSize(fontSize + 'px')
    }
  }

ePub电子书生成目录和定位信息

Book对象的钩子函数ready
  this.book.ready.then(() => {
    // 生成目录
    this.navigation = this.book.navigation
    // 生成Locations对象
    return this.book.locations.generate()
  }).then(result => {
    // 保存locations对象
    this.locations = this.book.locations
    // 标记电子书为解析完毕状态
    this.bookAvailable = true
  })
ePub电子书通过百分比进行定位
function onProgressChange(progress) {
  const percentage = progress / 100
  const location = percentage > 0 ? this.locations.cfiFromPercentage(percentage) : 0
  this.rendition.display(location)
}

HTML5 range控件

<input class="progress" 
       type="range"
       max="100"
       min="0"
       step="1"
       @change="onProgressChange($event.target.value)" 
       @input="onProgressInput($event.target.value)"
       :value="progress"
       :disabled="!bookAvailable"
       ref="progress">

相关文章

  • epub.js的使用

    npm安装 epub阅读器开发 ePub电子书解析和渲染 生成Book对象 通过Book.renderTo生成Re...

  • epubjs阅读器引擎

    epub.js是一个用于在浏览器中展示epub文档的JavaScript库,解决了epub电子书的解析、渲染、定位...

  • iconfont的使用(下载使用)

    1、下载文件 2、在生命周期中引入项目 beforeCreate () { var domModule = ...

  • Gson的使用--使用注解

    Gson为了简化序列化和反序列化的过程,提供了很多注解,这些注解大致分为三类,我们一一的介绍一下。 自定义字段的名...

  • 记录使用iframe的使用

    默认记录一下----可以说 这是我第一次使用iframe 之前都没有使用过; 使用方式: 自己开发就用了这几个属...

  • with的使用

    下面例子可以具体说明with如何工作: 运行代码,输出如下

  • this的使用

    什么是this? this是一个关键字,这个关键字总是返回一个对象;简单说,就是返回属性或方法“当前”所在的对象。...

  • this的使用

    JS中this调用有几种情况 一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象...

  • ==的使用

    积累日常遇到的编码规范,良好的编码习惯,持续更新。。。 日常使用==用于判断的时候,习惯性将比较值写前面,变量写后...

  • this的使用

    1.默认绑定,就是函数立即执行。 函数立即执行就是指向window,但是如果是node环境,就是指向全局conso...

网友评论

      本文标题:epub.js的使用

      本文链接:https://www.haomeiwen.com/subject/xcvidqtx.html