Highlight Nav Menu on scroll with JavaScript
HTML-код
- Опубликовано: 31 май 2024
- Many of you guys wanted to see a video on Highlighted nav menu. So here it is as you wanted. This is a really popular stuff that you might saw it in many website. Here when you scroll on web page, based on your scroll position the menu active item change dynamically. Today we are going make it with HTML, CSS and JavaScript.
Hope you will like it.
🔔subscribe and turn on the notification bell.
👉 source code: codepen.io/Web_Cifar/pen/LYRBbVE
Timestamps -
00:00 - Preview
01:57 - Layout(HTML/CSS)
10:42 - JavaScript
23:17 - Tutorial Conclusion
Follow Arfan 👇👇
Instagram: / shaifarfan08
Facebook: / shaifarfan08
🐱🏍 Support The Channel
Paypal : paypal.me/webcifar
▶ Also Watch :
Make a full website with HTML & CSS: • One Page Full Website ...
HTML & CSS Landing Page : • HTML & CSS Website Lan...
Mini Project for HTML & CSS : • Responsive Website Wit...
How To Make A WordPress website: • How To Make A Professi...
▶ Some useful Playlist :
HTML & CSS: • HTML & CSS
Vanilla JavaScript : • Vanilla JavaScript
Frontend Mentor Challenges: • Frontend Mentor Challe...
30days30submits Challenge: • 30days30submits
🌐 Join The Community :
Our website : webcifar.com/
Facebook Page : / webcifar
Facebook group : bit.ly/fb-group-webcifar
Instagram : / web_cifar
twitter : / webcifar
Github: github.com/WebCifar
#webcifar #highlightedMenu #javascript - Наука
life saver tutorial , thanks man, I've been struggling how to highlight section on navbar, I'm almost done with my project and this is the only thing I'm stuck with.
Just what I needed! I made minimalist navigation side bar, just lines to redirect my five sections, and was wondering how to change the background color when passing each section. thank you so much
The best tutorial about this on the web. Thanks very much for share this with us!
Great Great Great TUTORIAL! simple, concise, and intereting. Thank you! keep doing great stuff
Thanks so much sir
I brought the same logic into the startup I am currently building with React.
I used useRef instead and everything is smooth.
thanks again
have a wonderful day and your family
love from Seattle Washington
Thank you very much for this quick guide! It's awesome.
It is better to add class on tag instead of ?
Great tutorial! This is perfect and helps me a lot. Thank you so much👍
Great tutorial man! What I did take make it a little easier to maintain is instead of selecting all the li, I selected every "a" tag and got its href attribute then did a substring to remove the "#". Then i checked that against the "current" variable. that way you don't have to add classes to each li.
const navLi = document.querySelectorAll('.tabs__item a');
navLi.forEach(li => {
li.classList.remove('active');
const href = li.getAttribute('href').substring(1);
if (href === current) {
li.classList.add('active');
}
});
Great 👍
Excellent video, brilliant tutor, he explains things really well, clear well presented video, thanks!
thanks so much legend. Learned so much watching this.
Brilliant tutorial, very helpful and very well explained and demonstrated, great code, great teacher, thanks!
Wooooow! this was unbelievably helpful mate. Thanks ^^
Glad to hear it!
this tutorial is just perfect and what programmers are looking for. 👍
Thank you very much, it helped me a lot!
simple and functional! thanks for the great video
Thanks
thank you so much brother .. very well explained
Exactly what I needed! Thank you :)
Glad it helped!
Thanks for the tutorial! Worked for my project :D
Glad it helped!
Thanks so much. Helped a lot
Thanks for tutorial, it's very useful!
Thank you so much! You're the best!
You are welcome ❤️
Great tutorial, thank you!
Thanks for this! Helped me a lot!
Glad it helped!
thanks man i implemented this in react
당신은 천재입니다.
감사합니다 !
Thank you for sharing this tutorial, it really helped me
Glad to hear that!
Finally i got it.
Thanks
Excellent tutorial!
I have been looking for it for three days😶
Finally ❤️🙂
♥
Thank you so much!! Amazing video
Thank you very much! Your tutorial helped me a lot. At first I was kinda struggling troubleshooting, but it was the most fun part. It was worth it. ;> Really really thank u 🙏
Glad it helped!
Great vid, learned a lot!
It is extremely easy to understand.
Nailed It!
i have the problem that my sectiontop does not show, when i type "console.log".
my Sections are all diffrent in height.
the console.log on sections worked, so it knows where the sections are, but cant figure the offsetTop out.. Do you know why that is?
Thanks, this is what I want
Cool video, thanks. Small suggestion. If you set the value of current on 'home' (current = 'home') instead an empty string, than you'll have button-background on Home at the beginning and when you click again Home as well. Gr.
That’s great 👍
Thankyou this helped ne
Thank you so much 💝🥰
thanks. I like this tips
Thank you really it was a good one ..
Glad you liked it!
This really helped a lot 👏
Glad it was helpful.
thank you, learn a lot :D 🙏
Nice video! Thank you!
thanks thank you so much for the video it means a lot
Glad it helped
Great video, thank you so much.
You're very welcome!
really awesome bro
thank you so much ! thank you so much man
You're welcome!
Thanks for your tutorial learned a lot
Glad to hear that!
very helpfull, thanks alot !!
Thank you so much :)
awesome, thx man
thank you so much for this one.
You're very welcome!
Great video man keep up !
Thanks, you too!
hi how would you make it diff colours for each section?
This implementation is breaking when I change the screen resolution, can you help here
yu are my life save bro thanks
Great vid, just one error I noticed you forgotten 's' at 10:04 for transition
Thank you for the intel
Thanks bro!!
Thank you bro!
thank you sir it was really helpful
Glad it helped
Ótimo vídeo parabéns 👏.
Obrigado
puta video
very useful !!!!!!
thank you bro
very helpful thank you
Glad it was helpful!
thank you
Hello, thank you so much for this video - very helpful!
I wonder if you can help me : I want to add .scrollIntoView({ behavior: 'smooth', inline: "start" }) when clicked on nav item(so the correspondant section scrolls smoothly into view), but can't figure out how to get the "section" id to match li class..
navLi.forEach((li) => {
li.classList.remove("active");
if (li.classList.contains(current)) {
li.classList.add("active");
}
li.addEventListener("click", () => {
let liClass = li.getAttribute("class")
????????????
})
});
sorry if this is confusing >_>
Very good , thank you!
Our pleasure!
Don't work for me if section's height is in %... any advice to fix this issue?
Great video..had a question i am getting my section.OffsetTop as undefined.Can you help me with this?
My sections variable just has an empty list, so it does not pick up the sections.
What would happen if the nav li's had multiple sub-links ???
@WEB CIFAR
You are the best bro
Thanks
ধন্যবাদ ভাই
Awesome Bro! ❤️
Thanks 🔥
How to open collapse data when scroll down in js Please help
thanku so much bhai ...
Welcome Bhai ♥
Very good video.
Can you create the video of this in small screen and move navbar by base on scroll?
Be careful. You are adding a scroll listener, which fires a ton even on a short distance scroll. Every time the scroll event is fired you are iterating through a list of elements. This method could be extremely expensive. You should include logic in event listener callback to throttle how many times the iteration is done.
Hello dear .Your code is not working because Pageyoffset is deprecated what is it's alternative please ?
how to keep the selected nav color the same even after refreshing the page
I'm not seeing the footer in console.log. I see the home and about section but not the footer.
Thank you my brother
You are welcome
@@webcifar do you have a tutorial in javascript
helpful
Glad it helped
good
Thanks
What if i want to add class in the nav while scrolling in a particular section ?
Love from @Bangladesh
why is my home offsetTop returning 0?
Vsc theme?
It's cool ;)
🤟
When you are on home and click to footer: the animation ("active" so the red bg) is visible on all other nav button during the autoscroll idk if someone know what i mean :D also thx for this video
When I scroll to the bottom the last section is not beign detected. help please! Cool and really helpful video btw
bro, can u do it for react js?
nice, but please zoom in a little bit when recording, watching on mobile is quite difficult.
Noted. ❤
how can i get this cod
sir
I would love to start a youtube channel
could you tell with software you are using to record a course and which software you use to edit.
also which microphone and camera you are using
I really love creating content that is why I am building an application to share my content
That's awesome. I use OBS to record, DaVinci Resolve to edit and for the microphone I use BM800. For now, everything is working fine for me with this setup.
@@webcifar thanks a lot 🙏
There's a RUclipsr by the name of Bedimcode that implemented this feature in this video ruclips.net/video/6cidbUHNZRQ/видео.html but he did it differently from yours. I think yours was quicker to grasp because you explained what you were doing but he doesn't speak in his videos. I actually was able to break it down by watching your video and further reading and testing on my part. I may make a RUclips video on it , explaining how Bedimcode made his own work
There are tons of problems with routing etc.
Your tutorial does not work for me. I am using sublime 3.
Please explain properly i did'nt understand the logic in (if condtion) if anyone understand please explain this logic to me