-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
99 lines (91 loc) · 2.5 KB
/
index.html
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
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Presentation</title>
<style type="text/css">
html, body, #container {
margin: 0;
height: 100%;
width: 100%;
}
#container {
overflow: auto;
}
.pad {
flex-direction: column;
justify-content: center;
height: 100%;
display: flex;
text-align: center;
font-size: 80px;
color: gray;
}
img {
max-width: 80%;
}
::-webkit-scrollbar {
display: none;
}
</style>
<script type="text/javascript" src="./animatedScrollTo.js"></script>
<script type="text/javascript">
/* ------------- */
/* CONFIGURATION */
var stops = [0, 0.2, 0.4, 0.57, 0.76, 0.98];
var scrollSpeed = 500;
/* ------------- */
/* ------------- */
var NEXT_KEYS = [32 /*SPACE*/, 34 /*PAGE DOWN*/ , 39 /*RIGHT*/, 40 /*DOWN*/],
PREV_KEYS = [8 /*BACKSPACE*/, 33 /* PAGE UP*/, 37 /*LEFT*/, 38 /*UP*/];
document.addEventListener("DOMContentLoaded", function(event) {
var image = document.getElementById("presentation");
var container = document.getElementById("container");
scrollTo(container, 0);
document.addEventListener("keydown", function(event) {
var isNext = NEXT_KEYS.indexOf(event.keyCode) > -1,
isPrev = PREV_KEYS.indexOf(event.keyCode) > -1;
if(isNext || isPrev) {
var docPos = container.scrollTop,
docHeight = container.offsetHeight,
docBottom = docPos + docHeight,
imgStart = image.offsetTop,
imgHeight = image.height,
done = (docBottom - imgStart) / imgHeight,
prev;
if(isPrev) {
done -= 1 / imgHeight;
prev = 1;
} else {
done += 1 / imgHeight;
prev = 0;
}
console.log("current state is", done, "at", docPos);
function scroll(percentage) {
var y = (percentage * imgHeight) + imgStart - docHeight;
console.log("scrolling to", percentage, "at", y);
animatedScrollTo(container, y, scrollSpeed);
}
for(var i=0; i < stops.length; i++) {
if(stops[i] > done){
scroll(stops[i - prev]);
break;
}
}
event.preventDefault();
} else {
console.log(event);
}
});
});
</script>
</head>
<body>
<div id="container">
<div class="pad">↓</div>
<center><img id="presentation" src="presentation.jpg"></center>
</div>
</body>
</html>