Skip to content

Commit

Permalink
add smooth scroll to some sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Larkin committed Jul 30, 2024
1 parent c6ee431 commit cac1d03
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions assets/js/smooth-scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', function() {
const menuLinks = document.querySelectorAll('nav a');

menuLinks.forEach(link => {
link.addEventListener('click', function(e) {
const href = this.getAttribute('href');

// Skip smooth scroll for external links, Home, and CV
if (!href.startsWith('#') || href === '#' || this.classList.contains('no-smooth-scroll')) {
return;
}

e.preventDefault();

const targetId = href.replace('#', '');
const targetElement = document.getElementById(targetId);

if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});
7 changes: 6 additions & 1 deletion config/_default/menus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ main:
- name: Home
url: /
weight: 10
params:
class: no-smooth-scroll
- name: Research
url: /#papers
weight: 11
Expand All @@ -16,9 +18,12 @@ main:
- name: CV
url: experience/
weight: 20
params:
class: no-smooth-scroll
- name: Projects
url: projects/
weight: 30
- name: Contact
url: /#contact
weight: 60
weight: 60

1 change: 1 addition & 0 deletions layouts/partials/hooks/body-end/custom-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="{{ "js/smooth-scroll.js" | relURL }}"></script>

0 comments on commit cac1d03

Please sign in to comment.