-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (26 loc) · 1003 Bytes
/
index.js
File metadata and controls
33 lines (26 loc) · 1003 Bytes
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
const getCurrentURL = (event) => event.target.URL;
window.addEventListener("load", (event) => {
const currentURL = getCurrentURL(event);
const scrollPositionY = Number(window.localStorage.getItem(currentURL));
if (scrollPositionY) {
drawBookmark(scrollPositionY);
window.scrollTo(0, scrollPositionY);
}
});
window.addEventListener("unload", (event) => {
const scrollPositionY = window.scrollY;
const currentURL = getCurrentURL(event);
window.localStorage.setItem(currentURL, scrollPositionY);
});
const drawBookmark = (scrollPositionY) => {
const $body = window.document.querySelector("body");
const $wrapper = document.createElement("div");
$wrapper.style.display = "block";
$wrapper.style.border = "10px solid blue";
$wrapper.style.position = "absolute";
$wrapper.style.top = `${scrollPositionY}px`;
const $text = document.createElement("div");
$text.innerHTML = `<h1>This is sticker</h1>`;
$wrapper.appendChild($text);
$body.appendChild($wrapper);
};