Skip to content

Commit

Permalink
fix: 🐛 adjust scrolling to account for header
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunes5thmoon committed Jun 27, 2024
1 parent f218ea9 commit dc73590
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ <h1 class="post-title">{{ page.title }}</h1>
/* position: fixed; */
/* top: 0;
right: 0; */
padding-top: 20px;
padding-top: 0px;
/* background-color: lightblue; */
position: -webkit-sticky;
float: left;
position: sticky;
top: 0;
top: 60px;
}
.sidebar div {
padding: 8px;
Expand All @@ -39,7 +39,7 @@ <h3>Table of Contents</h3>
</div>
<div class="main">
<div id="markdown-content">
{{ content | inject_anchors }}
{{ content | inject_anchors}}
</div>
</div>
</div>
Expand All @@ -60,3 +60,38 @@ <h3>Table of Contents</h3>
{% endif %}

</div>

<script>
document.addEventListener("DOMContentLoaded", function() {
// Function to adjust scroll position
function adjustScroll() {
setTimeout(function() {
window.scrollTo(window.scrollX, window.scrollY - 60); // Adjust based on your header height
}, 100);
}

// Adjust scroll on page load if there's a hash in the URL
if (window.location.hash) {
adjustScroll();
}

// Prevent duplicate scroll adjustment on link click
var mainLinks = document.querySelectorAll('.main a');
mainLinks.forEach(function(anchor) {
anchor.addEventListener('click', function(event) {
if (window.location.hash) {
adjustScroll();
}
});
});


// Adjust scroll when TOC link is clicked
var tocLinks = document.querySelectorAll('.sidebar a[href^="#"]');
tocLinks.forEach(function(anchor) {
anchor.addEventListener('click', function(event) {
adjustScroll();
});
});
});
</script>

0 comments on commit dc73590

Please sign in to comment.