-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bookmarks): add bookmark navigation and placeholder image
• Added bookmark navigation functionality with smooth scrolling • Implemented active state highlighting for bookmark nav items • Created a new SVG placeholder image for bookmarks • Updated bookmarks layout to include navigation data attributes • Integrated bookmarkNav.js script for handling navigation logic
- Loading branch information
1 parent
824397c
commit 28c161b
Showing
12 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.bookmark-nav-item { | ||
&.active { | ||
background-color: var(--second-background-color); | ||
color: var(--primary-color); | ||
border-color: var(--second-background-color); | ||
transform: scale(1.02); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
export default function initBookmarkNav() { | ||
const navItems = document.querySelectorAll('.bookmark-nav-item'); | ||
const sections = document.querySelectorAll('section[id]'); | ||
|
||
if (!navItems.length || !sections.length) return; | ||
|
||
// Throttle function | ||
function throttle(func, limit) { | ||
let inThrottle; | ||
return function() { | ||
const args = arguments; | ||
const context = this; | ||
if (!inThrottle) { | ||
func.apply(context, args); | ||
inThrottle = true; | ||
setTimeout(() => inThrottle = false, limit); | ||
} | ||
} | ||
} | ||
|
||
function setActiveNavItem() { | ||
const fromTop = window.scrollY + 100; | ||
let currentSection = null; | ||
|
||
sections.forEach(section => { | ||
const sectionTop = section.offsetTop; | ||
const sectionHeight = section.offsetHeight; | ||
|
||
if (fromTop >= sectionTop && fromTop < sectionTop + sectionHeight) { | ||
currentSection = section; | ||
} | ||
}); | ||
|
||
navItems.forEach(item => { | ||
item.classList.remove('bg-second-background-color'); | ||
if (currentSection && item.getAttribute('data-category') === currentSection.getAttribute('id')) { | ||
item.classList.add('bg-second-background-color'); | ||
} | ||
}); | ||
} | ||
|
||
// // Handle click events on nav items | ||
// navItems.forEach(item => { | ||
// item.addEventListener('click', (e) => { | ||
// e.preventDefault(); | ||
// const targetId = item.getAttribute('data-category'); | ||
// const targetSection = document.getElementById(targetId); | ||
// if (targetSection) { | ||
// targetSection.scrollIntoView(); | ||
// } | ||
// }); | ||
// }); | ||
|
||
// Throttle scroll handler to run at most every 100ms | ||
window.addEventListener('scroll', throttle(setActiveNavItem, 100)); | ||
|
||
// Initial check | ||
setActiveNavItem(); | ||
} | ||
|
||
try { | ||
swup.hooks.on("page:view", initBookmarkNav); | ||
} catch (e) {} | ||
|
||
document.addEventListener("DOMContentLoaded", initBookmarkNav); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters