Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smooth scrolling effect to navigation links #1799

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,20 @@ <h1 class="text-xs uppercase font-semibold tracking-widest">Menu</h1>

<div>
<ul class="hidden md:flex items-center gap-10 uppercase text-xs font-semibold tracking-wider ">
<li>
<a href="./index.html"
class="pb-3 hover:text-black relative font-semibold after:content-[''] after:bottom-0 after:h-1 after:w-0 after:left-0 after:absolute after:bg-black hover:after:w-full after:ease-in-out after:duration-300 ">Home</a>
<li>
<a href="./index.html"
class="pb-3 hover:text-black relative font-semibold after:content-[''] after:bottom-0 after:h-1 after:w-0 after:left-0 after:absolute after:bg-black hover:after:w-full after:ease-in-out after:duration-300">
Home
</a>
</li>

<li>
<a href="#mentalHealthComponent"
class="pb-3 hover:text-black relative font-semibold after:content-[''] after:bottom-0 after:h-1 after:w-0 after:left-0 after:absolute after:bg-black hover:after:w-full after:ease-in-out after:duration-300 ">
Mental Health Problems </a>
<a id="scrollToMentalHealth" href="#mentalHealthComponent"
class="pb-3 hover:text-black relative font-semibold after:content-[''] after:bottom-0 after:h-1 after:w-0 after:left-0 after:absolute after:bg-black hover:after:w-full after:ease-in-out after:duration-300">
Mental Health Problems
</a>
</li>

<li>
<a href="./Blogs/Blog.html"
class="pb-3 hover:text-black relative font-semibold after:content-[''] after:bottom-0 after:h-1 after:w-0 after:left-0 after:absolute after:bg-black hover:after:w-full after:ease-in-out after:duration-300 ">Power
Expand Down
51 changes: 34 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
let dropMenuLinks = document.querySelector('.dropMenuLinks');
let indexOpenDropDown = document.querySelector('.indexOpenDropDown');
let closeDropDown = document.querySelector('.closeDropDown');
let heroSection = document.querySelector('.heroSection');
let dropMenuLinks = document.querySelector(".dropMenuLinks");
let indexOpenDropDown = document.querySelector(".indexOpenDropDown");
let closeDropDown = document.querySelector(".closeDropDown");
let heroSection = document.querySelector(".heroSection");

indexOpenDropDown.onclick = () => {
dropMenuLinks.style.right = 0;
heroSection.style.zIndex = `1`;
}
};

closeDropDown.onclick = () => {
dropMenuLinks.style.right = `-2000px`;
heroSection.style.zIndex = `50`;

}
};

function subscribe() {
var email = document.getElementById('email').value;
var email = document.getElementById("email").value;

// Validate email address
if (!validateEmail(email)) {
showPopup('Please enter a valid email address.');
showPopup("Please enter a valid email address.");
return;
}

// send the email address to the admin
// For demonstration, let's just show a confirmation message
showPopup('You have successfully subscribed with email: ' + email);
showPopup("You have successfully subscribed with email: " + email);
}

function validateEmail(email) {
Expand All @@ -35,11 +34,29 @@ function validateEmail(email) {
}

function showPopup(message) {
var popup = document.getElementById('popup');
var popuptext = document.getElementById('popuptext');
var popup = document.getElementById("popup");
var popuptext = document.getElementById("popuptext");
popuptext.textContent = message;
popup.classList.add('show');
setTimeout(function() {
popup.classList.remove('show');
popup.classList.add("show");
setTimeout(function () {
popup.classList.remove("show");
}, 3000); // Hide popup after 3 seconds
}

const anchor = document.getElementById("scrollToMentalHealth");

if (anchor) {
anchor.addEventListener("click", function (event) {
event.preventDefault();

const targetId = this.getAttribute("href").substring(1);
const targetElement = document.getElementById(targetId);

if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
}