Skip to content

Commit edabe02

Browse files
committed
consistent scroll on all pages
1 parent d7fd69a commit edabe02

File tree

3 files changed

+90
-16
lines changed

3 files changed

+90
-16
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class="navbar-link">Add Profile</a>
3535
<a href="#" class="navbar-link">Tools</a>
3636
<a href="./pages/events.html" class="navbar-link">Events</a>
37-
<a href="pages/blog.html" class="navbar-link">Learn</a>
37+
<a href="./pages/blog.html" class="navbar-link">Learn</a>
3838
<a href="./pages/compare.html" class="navbar-link">Compare</a>
3939
<a href="login.html" class="navbar-link">Login</a>
4040

pages/events.html

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
</a>
2121
<div class="navbar-right">
2222
<a href="githubbadge.html" class="navbar-link">Github-Badge</a>
23-
<a href="https://github.com/recodehive/awesome-github-profiles/issues/new?assignees=&labels=%E2%9E%95+profile&projects=&template=add_profile.md&title=Add+Profile%3A+"
23+
<a href="https://github.com/recodehive/awesome-github-profiles/issues/new?assignees=&labels=%E2%9E%95+profile&projects=&template=add_profile.md&title=Add+Profile%3A+"
2424
class="navbar-link">Add Profile</a>
25-
<a href="#" class="navbar-link">Tools</a>
26-
<a href="events.html" class="navbar-link">Events</a>
27-
<a href="blog.html" class="navbar-link">Learn</a>
28-
<a href="compare.html" class="navbar-link">Compare</a>
29-
25+
<a href="#" class="navbar-link">Tools</a>
26+
<a href="events.html" class="navbar-link">Events</a>
27+
<a href="blog.html" class="navbar-link">Learn</a>
28+
<a href="compare.html" class="navbar-link">Compare</a>
29+
3030
<div class="toggle-switch">
3131
<input type="checkbox" id="theme-toggle">
3232
<label for="theme-toggle">
@@ -155,19 +155,20 @@ <h5>
155155

156156
<div class="footer-bottom">
157157
<div class="footer-container">
158-
<p class="footer-copyright">
159-
&copy; <span id="dynamic-year"></span> Recode-Hive. Made with 🖤️ by the community. All rights reserved.
160-
</p>
158+
<p class="footer-copyright">
159+
&copy; <span id="dynamic-year"></span> Recode-Hive. Made with 🖤️ by the community. All rights reserved.
160+
</p>
161161
</div>
162-
</div>
163-
164-
<script>
162+
</div>
163+
164+
<script>
165165
document.getElementById("dynamic-year").textContent = new Date().getFullYear();
166-
</script>
167-
166+
</script>
167+
168168
</footer>
169169

170170
<script src="../scripts/script.js"></script>
171+
<script src="../scripts/ScrollToTop.js"></script>
171172
<script src="../scripts/dark-mode.js"></script>
172173
<script src="../scripts/hamburger.js"></script>
173174
<script>
@@ -228,6 +229,53 @@ <h5>
228229
// Example function to call when content div is in view
229230

230231
});
232+
document.addEventListener('DOMContentLoaded', () => {
233+
const contentDiv1 = document.getElementById('scroll1');
234+
const contentDiv2 = document.getElementById('scroll2');
235+
const contentDiv3 = document.getElementById('scroll3');
236+
237+
// Set initial height to 0% for the line divs
238+
contentDiv1.style.height = '0%';
239+
contentDiv2.style.height = '0%';
240+
contentDiv3.style.height = '0%';
241+
242+
// Function to expand the line when it comes into view
243+
function handleIntersection(entries, observer) {
244+
entries.forEach(entry => {
245+
if (entry.isIntersecting) {
246+
entry.target.style.height = '100%'; // Set height to 100% when the element is in view
247+
observer.unobserve(entry.target); // Stop observing after it animates
248+
}
249+
});
250+
}
251+
252+
// IntersectionObserver configuration
253+
const observer = new IntersectionObserver(handleIntersection, {
254+
root: null, // Use the viewport as the root
255+
rootMargin: '0px', // Adjust margin if needed
256+
threshold: 0.1 // Trigger when 10% of the target is visible
257+
});
258+
259+
// Start observing the elements
260+
observer.observe(contentDiv1);
261+
observer.observe(contentDiv2);
262+
observer.observe(contentDiv3);
263+
});
264+
document.addEventListener('DOMContentLoaded', () => {
265+
// Select the "Events" link from the navbar
266+
const eventsLink = document.querySelector('.navbar-link[href="events.html"]');
267+
268+
// Add an event listener to the "Events" link
269+
eventsLink.addEventListener('click', (event) => {
270+
event.preventDefault(); // Prevent the default behavior of the link
271+
272+
// Smooth scroll to the top of the page
273+
window.scrollTo({
274+
top: 0,
275+
behavior: 'smooth' // Enables smooth scrolling
276+
});
277+
});
278+
});
231279
</script>
232280
</body>
233281

scripts/ScrollToTop.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,30 @@ function updateProgressBar() {
5151
var scrollPercent = (scrollTop / scrollHeight) * 100;
5252

5353
document.getElementById("progressBar").style.width = scrollPercent + "%";
54-
}
54+
}
55+
56+
document.addEventListener("DOMContentLoaded", function () {
57+
const navbarLinks = document.querySelectorAll(".navbar-link");
58+
59+
// Function to check if the user is already on the current page
60+
function isSamePage(link) {
61+
return window.location.pathname === link.pathname;
62+
}
63+
64+
// Smooth scroll to top function
65+
function scrollToTop() {
66+
window.scrollTo({
67+
top: 0,
68+
behavior: "smooth",
69+
});
70+
}
71+
72+
navbarLinks.forEach(link => {
73+
link.addEventListener("click", function (event) {
74+
if (isSamePage(this)) {
75+
event.preventDefault(); // Prevent default link behavior if it's the same page
76+
scrollToTop();
77+
}
78+
});
79+
});
80+
});

0 commit comments

Comments
 (0)