我想知道如何使用 Epub.js 转到 Epub 中的特定页面。
通过在当前页面中点击时记录重新定义对象,我可以获得位置,但之后我不知道如何使用它。
book.ready.then(function () {
var saveBookMark = function () {
console.log(rendition.currentLocation());
// I could save the location here
};
var addBookMark = document.getElementById('add-bookmark');
addBookMark.addEventListener("click", saveBookMark, false);
});
如果我在使用之前获得的位置后执行此操作:
var bookmark = {
href: 'Text/Chapter1_06a.xhtml',
};
history.pushState({}, '', "?loc=" + encodeURIComponent(bookmark.href));
我可以转到章节,但不能转到捕获书签的页面。
这是当前页面点击重登得到的对象。
redention.location = {
end: {
cfi: "epubcfi(/6/26[Chapter1_06a.xhtml]!/4/2/124/10/3:22)",
displayed: {page: 8, total: 8},
href: "Text/Chapter1_06a.xhtml",
index: 12,
location: -1,
percentage: 0,
},
start: {
index: 12,
href: "Text/Chapter1_06a.xhtml",
cfi: "epubcfi(/6/26[Chapter1_06a.xhtml]!/4/2/110/1:242)",
displayed: {…},
location: -1,
…
}
}
最佳答案
您已经展示了您的代码片段,但不是全部。看起来您有错字:rendition
与 redention
不同。
无论如何,rendition.gotoCfi(some_cfi)
应该可以解决问题。您甚至可能不需要 rendition
对象;你也可以调用 book.goto(some_cfi)
。
关于javascript - 如何转到 Epubjs 中的特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57949506/