Skip to content

Commit 1bfc21e

Browse files
committed
minimap respond to page scroll
1 parent e7e61c8 commit 1bfc21e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ svg text {
5353
display:block;
5454
}
5555

56+
#graph button {
57+
position:absolute;
58+
}
59+
5660
#toggle-minimap {
5761
display:block;
5862
cursor:pointer;

js/minimap.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Minimap = (function() {
66
let ctx;
77
let h;
88
let w;
9+
let dy = 0;
910

1011
const RECT_HEIGHT = 3;
1112
const PADDING = 3;
@@ -20,12 +21,16 @@ const Minimap = (function() {
2021
const ROW_WIDTH = Config.svgWidth;
2122
const r = w / ROW_WIDTH;
2223

23-
ctx.clearRect(0,0,w,h);
24+
ctx.clearRect(0,0,w,h + dy);
2425
ctx.globalAlpha = 1;
25-
26+
ctx.strokeStyle = 'white';
27+
28+
let scrollIndex = 0;
29+
2630
// draw word
2731
let slots = [];
2832
rows.forEach(function(row, i) {
33+
if (row.ry < document.body.scrollTop) { scrollIndex = i; }
2934
slots[i] = (slots[i - 1] || 0) + row.maxSlots + 1;
3035

3136
row.words.forEach(function(word) {
@@ -77,6 +82,9 @@ const Minimap = (function() {
7782
}
7883
});
7984

85+
dy = (slots[scrollIndex - 1] || 0) * RECT_HEIGHT + scrollIndex * PADDING;
86+
ctx.setTransform( 1, 0, 0, 1, 0, -dy );
87+
8088
window.requestAnimationFrame(update);
8189
}
8290

0 commit comments

Comments
 (0)