|
56 | 56 | prevEl: '.swiper-button-prev', |
57 | 57 | }, |
58 | 58 | }); |
| 59 | + |
| 60 | + // On the Home, Feature section: scroll to the top of the tab-content |
| 61 | + // everytime tab switches. |
59 | 62 |
|
| 63 | + $('button[data-toggle="tab"]').on('shown.bs.tab', function (e) { |
| 64 | + |
| 65 | + // Find the container holding your tab content |
| 66 | + const tabContent = document.querySelector('.tab-content'); |
| 67 | + |
| 68 | + if (tabContent) { |
| 69 | + // Scroll the top of the tab content into view smoothly |
| 70 | + tabContent.scrollIntoView({ |
| 71 | + behavior: 'smooth', |
| 72 | + block: 'start' |
| 73 | + }); |
| 74 | + } |
| 75 | + }); |
| 76 | + |
| 77 | + // Features Page: |
| 78 | + |
| 79 | + const spyTarget = '#features-menu'; |
| 80 | + const midScreenOffset = 450; |
| 81 | + let finalDestinationId = null; |
| 82 | + let isNavClick = false; |
| 83 | + |
| 84 | + // 1. Add scrollspy to Body |
| 85 | + $('body').scrollspy({ target: spyTarget, offset: midScreenOffset }); |
| 86 | + |
| 87 | + // 2. Listen for clicks on the Bootstrap Nav links |
| 88 | + $(`${spyTarget} .nav-link`).on('click', function () { |
| 89 | + // Save the exact ID the user clicked on (e.g., "#services") |
| 90 | + finalDestinationId = this.hash; |
| 91 | + isNavClick = true; |
60 | 92 |
|
| 93 | + $('body').scrollspy('dispose'); |
| 94 | + window.location.hash = finalDestinationId; |
| 95 | + |
| 96 | + // Visually lock the active class onto this clicked item immediately |
| 97 | + $(`${spyTarget} .nav-link`).removeClass('active'); |
| 98 | + $(this).addClass('active'); |
| 99 | + }); |
| 100 | + |
| 101 | + window.addEventListener('scrollend', function () { |
| 102 | + // Only run this logic if the scroll came from clicking a nav item |
| 103 | + if (!isNavClick) return; |
| 104 | + |
| 105 | + isNavClick = false; |
| 106 | + |
| 107 | + // 6. ARRIVAL! The native browser scroll is done. |
| 108 | + // Re-initialize ScrollSpy so it tracks normal manual mouse wheel scrolling again. |
| 109 | + $('body').scrollspy({ target: spyTarget, offset: midScreenOffset }); |
| 110 | + $('body').scrollspy('refresh'); |
| 111 | + }); |
| 112 | + |
61 | 113 | })(jQuery); // End of use strict |
0 commit comments