Skip to content

Commit da3d2c6

Browse files
committed
updated: created dynamic scrolling for specified sections
1 parent a330025 commit da3d2c6

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

archive/archive.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,26 @@
1616

1717
</div>
1818
<script src="./js/archive.js"></script>
19+
<script>
20+
function scrollToHash() {
21+
if (window.location.hash) {
22+
const el = document.querySelector(window.location.hash);
23+
if (el) {
24+
el.scrollIntoView({ behavior: "smooth" });
25+
return true;
26+
}
27+
}
28+
return false;
29+
}
30+
if (!scrollToHash()) {
31+
const observer = new MutationObserver(() => {
32+
if (scrollToHash()) {
33+
observer.disconnect();
34+
}
35+
});
36+
observer.observe(document.body, { childList: true, subtree: true });
37+
}
38+
</script>
39+
1940
</body>
2041
</html>

archive/js/archive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fetch('../blog-posts/posts.json').then(response => {
77
return response.json();
88
}).then(data => {
99
let blogPosts = data.posts;
10-
console.log(blogPosts);
1110
let followingPosts = blogPosts.slice(1);
1211

1312
followingPosts.forEach(post => {
@@ -30,6 +29,7 @@ fetch('../blog-posts/posts.json').then(response => {
3029
blogTitle.innerText = post["title"];
3130
blogDate.innerText = post["date"];
3231
blogSong.innerHTML = post["song"];
32+
blogContent.id = post["id"];
3333

3434
blogContent.appendChild(blogTitle);
3535
blogContent.appendChild(blogDate);

0 commit comments

Comments
 (0)