我想知道如何使用 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));
我可以转到章节,但不能转到书签被捕获的页面。
这是当前页面点击redenion得到的对象。
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)
。