File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed
Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ document.addEventListener("DOMContentLoaded", function () {
55
66 // Basic sticky navigation
77 const handleScroll = ( ) => {
8- if ( window . scrollY > heroSection . offsetHeight ) {
8+ const scrollPosition = window . scrollY ;
9+ if ( scrollPosition > heroSection . offsetHeight ) {
910 nav . classList . add ( "sticky" ) ;
1011 } else {
1112 nav . classList . remove ( "sticky" ) ;
@@ -25,19 +26,18 @@ document.addEventListener("DOMContentLoaded", function () {
2526 // Close menu
2627 navCheckbox . checked = false ;
2728
28- // Calculate offset based on section
29- const offset = targetId === "#contact" ? 0 : 80 ;
29+ // Calculate proper offset including nav height
30+ const navHeight = nav . offsetHeight ;
31+ const offset = targetId === "#contact" ? navHeight : navHeight + 32 ;
3032
31- // Smooth scroll
33+ // Smooth scroll with adjusted position
3234 window . scrollTo ( {
3335 top : targetSection . offsetTop - offset ,
3436 behavior : "smooth" ,
3537 } ) ;
3638
37- // Update URL after scroll completes
38- setTimeout ( ( ) => {
39- window . location . hash = targetId ;
40- } , 800 ) ;
39+ // Update URL without jumping
40+ window . history . pushState ( null , "" , targetId ) ;
4141 } ;
4242
4343 // Event listeners
Original file line number Diff line number Diff line change 4444 transition : all 0.3s ease;
4545}
4646
47+ html {
48+ scroll-padding-top : 100px ; /* Prevents content from going under sticky nav */
49+ }
50+
4751.nav-container .sticky {
4852 position : fixed;
4953 top : 16px ;
You can’t perform that action at this time.
0 commit comments