epubjs 在线阅读epub文件

  • Post author:
  • Post category:其他


1.epubjs注册事件

book.spine.hooks.serialize // Section is being converted to text
book.spine.hooks.content // Section has been loaded and parsed
rendition.hooks.render // Section is rendered to the screen
rendition.hooks.content // Section contents have been loaded
rendition.hooks.unloaded // Section contents are being unloaded

2.epubjs监听事件

rendition.on("started",()=>{})
rendition.on("attached",()=>{})
rendition.on("displayed",()=>{})
rendition.on("displayError",()=>{})
rendition.on("rendered",()=>{})
rendition.on("removed",()=>{})
rendition.on("resized",()=>{})
rendition.on("orientationchange",()=>{})
rendition.on("locationChanged",()=>{})
rendition.on("relocated",()=>{})
rendition.on("selected",()=>{})
rendition.on("markClicked",()=>{})
rendition.on("keyup",()=>{})

3.打开模式

//双栏模式
 this.state.rendition = book.renderTo("viewer", {
                        width: "100%",
                        height: "100%",
                        allowScriptedContent:true //是否允许插入外部文件
                    });
  //双栏单页模式
  this.state.rendition = book.renderTo("viewer", {
                        width: "100%",
                        height: "100%",
                        spread: "none",
                    });
                    
        //滚动分页模式
  this.state.rendition = book.renderTo("viewer", {
                        width: "100%",
                        height: "100%",
                   flow: "scrolled-doc"
  })     
     //滚动分页继续加载模式   
    this.state.rendition = book.renderTo("viewer", {
                        width: "100%",
                        height: "100%",
                   flow: "scrolled-doc",
                    manager: "continuous",
  })        

//获取封面信息,作者等

 book.loaded.metadata.then(function(meta){
      var $title = document.getElementById("title");
      var $author = document.getElementById("author");
      var $cover = document.getElementById("cover");
      var $nav = document.getElementById('navigation');

      $title.textContent = meta.title;
      $author.textContent = meta.creator;
      if (book.archive) {
        book.archive.createUrl(book.cover)
          .then(function (url) {
            $cover.src = url;
          })
      } else {
        $cover.src = book.cover;
      }

      // if ($nav.offsetHeight + 60 < window.innerHeight) {
      //   $nav.classList.add("fixed");
      // }

    });

//获取提纲

  book.loaded.navigation.then((toc) => {})

//注册主题

  this.state.rendition.themes.register("tan",”http://xxxx.css“);
                this.state.rendition.themes.select("normal");

//设置个性样式

 renditionApi.themes.default({
                        "*":{}
                    })



版权声明:本文为weixin_46472377原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。