Skip to content

Commit

Permalink
Merge pull request #266 from bearsunday/ref
Browse files Browse the repository at this point in the history
目次の追加と表現の調整
  • Loading branch information
koriym authored Apr 21, 2024
2 parents 98e0b8c + b187d7a commit 4b5897b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 108 deletions.
1 change: 1 addition & 0 deletions _includes/manuals/1.0/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-6074569-8', 'bearsunday.github.io'); ga('send', 'pageview');
</script>
<script src="/js/scroller.js"></script>
<script src="https://www.google-analytics.com/analytics.js" async defer></script>
{% if page.category == 'Manual' %}
<script src="/js/generate-table-of-contents/index.min.js"></script>
Expand Down
23 changes: 23 additions & 0 deletions js/scroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Added smooth scroll behavior to anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
const targetTop = target.getBoundingClientRect().top + window.pageYOffset;
const targetId = this.getAttribute('href');
history.pushState({ id: targetId, top: targetTop }, null, targetId);
target.scrollIntoView({
behavior: 'smooth'
});
});
});

window.addEventListener('popstate', function(e) {
if (e.state && e.state.id) {
const target = document.querySelector(e.state.id);
window.scrollTo({
top: e.state.top,
behavior: 'smooth'
});
}
});
Loading

0 comments on commit 4b5897b

Please sign in to comment.