forked from futurepress/epub.js
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathscrolled.html
More file actions
92 lines (81 loc) · 2.71 KB
/
scrolled.html
File metadata and controls
92 lines (81 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="epub.js,epub-js,scrolled,example">
<meta name="description" content="scrolling a document">
<meta http-equiv="Permissions-Policy" content="interest-cohort=()" />
<link rel="icon" type="image/png" href="../assets/img/favicon.png">
<link rel="stylesheet" type="text/css" href="../assets/css/main.css">
<script src="../dist/epub.js"></script>
<title>epub-js-examples : Scrolling a document</title>
</head>
<body id="app">
<header>
<nav>
<ul>
<li class="l-item"><a href="./">Examples</a></li>
<li class="r-item">
<a href="https://github.com/intity/epub-js/blob/master/examples/scrolled.html" id="gh-link" target="_blank"></a>
</li>
</ul>
</nav>
</header>
<main id="content" class="ltr" dir="ltr">
<div id="viewport" class="scrolled">
<div id="loader"></div>
</div>
<a id="prev" href="#prev" class="arrow"></a>
<a id="next" href="#next" class="arrow"></a>
</main>
<footer></footer>
<script>
const loader = document.getElementById("loader")
const prev = document.getElementById("prev")
const next = document.getElementById("next")
const book = ePub("../assets/alice/")
const rendition = book.renderTo("viewport", {
flow: "scrolled",
width: 908,
height: window.innerHeight - 160
})
book.opened.then(() => {
loader.style.display = "none"
})
next.onclick = (e) => {
rendition.next()
e.preventDefault()
}
prev.onclick = (e) => {
rendition.prev();
e.preventDefault();
}
const update = (loc) => {
prev.style.display = loc.atStart ? "none" : "block"
next.style.display = loc.atEnd ? "none" : "block"
}
const keybinding = (e) => {
switch (e.key) {
case "ArrowLeft":
rendition.prev()
break;
case "ArrowRight":
rendition.next()
break;
}
}
rendition.display().then(() => {
document.onkeyup = keybinding
rendition.on("keyup", keybinding)
})
rendition.on("attached", () => {
console.log(rendition)
})
rendition.on("relocated", (location) => {
update(location)
console.log(location)
})
</script>
</body>
</html>