smooth scroll homepage link
This commit is contained in:
@@ -16,8 +16,9 @@ let isDeleting = false;
|
|||||||
|
|
||||||
function type() {
|
function type() {
|
||||||
const currentText = text.substring(0, index);
|
const currentText = text.substring(0, index);
|
||||||
typewriterElement.textContent = currentText;
|
if (typewriterElement) {
|
||||||
|
typewriterElement.textContent = currentText;
|
||||||
|
}
|
||||||
if (!isDeleting && index < text.length) {
|
if (!isDeleting && index < text.length) {
|
||||||
index++;
|
index++;
|
||||||
setTimeout(type, 100);
|
setTimeout(type, 100);
|
||||||
@@ -28,7 +29,9 @@ function type() {
|
|||||||
|
|
||||||
// Start typing effect on load
|
// Start typing effect on load
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
setTimeout(type, 500);
|
if (typewriterElement) {
|
||||||
|
setTimeout(type, 500);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Smooth scrolling for anchor links
|
// Smooth scrolling for anchor links
|
||||||
@@ -56,3 +59,18 @@ document.querySelectorAll('a[href^="/#"]').forEach(anchor => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Smooth scrolling for the main home link
|
||||||
|
document.querySelectorAll('a[href="/"]').forEach(anchor => {
|
||||||
|
anchor.addEventListener('click', function(e) {
|
||||||
|
// If we are already on the homepage
|
||||||
|
if (window.location.pathname === '/') {
|
||||||
|
e.preventDefault(); // Prevent the page from reloading
|
||||||
|
// Scroll smoothly to the top of the page
|
||||||
|
window.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
behavior: 'smooth'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user