Highlight Nav Menu on scroll with JavaScript

  Рет қаралды 51,992

WEB CIFAR

WEB CIFAR

Күн бұрын

Пікірлер: 135
@JoshPalmeroc
@JoshPalmeroc 3 жыл бұрын
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'); } });
@webcifar
@webcifar 3 жыл бұрын
Great 👍
@Matin1999_unique
@Matin1999_unique 3 жыл бұрын
this tutorial is just perfect and what programmers are looking for. 👍
@AjSarco
@AjSarco 3 жыл бұрын
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.
@MrTomequ
@MrTomequ 3 жыл бұрын
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.
@webcifar
@webcifar 3 жыл бұрын
That’s great 👍
@gaurishnaik8288
@gaurishnaik8288 2 жыл бұрын
Thankyou this helped ne
@skullnecroze
@skullnecroze Жыл бұрын
The best tutorial about this on the web. Thanks very much for share this with us!
@gabrielfono844
@gabrielfono844 2 жыл бұрын
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
@tusharkadian
@tusharkadian 3 жыл бұрын
It is better to add class on tag instead of ?
@ichigolei4637
@ichigolei4637 2 жыл бұрын
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
@kunalpatil1250
@kunalpatil1250 2 жыл бұрын
thanks man i implemented this in react
@photoinshot1355
@photoinshot1355 9 ай бұрын
Brilliant tutorial, very helpful and very well explained and demonstrated, great code, great teacher, thanks!
@esmailkhalifa3984
@esmailkhalifa3984 3 жыл бұрын
I have been looking for it for three days😶 Finally ❤️🙂
@webcifar
@webcifar 3 жыл бұрын
@MrWebDesignerAnas
@MrWebDesignerAnas 3 жыл бұрын
thank you sir it was really helpful
@webcifar
@webcifar 3 жыл бұрын
Glad it helped
@freddymoreno9300
@freddymoreno9300 2 жыл бұрын
Great Great Great TUTORIAL! simple, concise, and intereting. Thank you! keep doing great stuff
@rosehope5376
@rosehope5376 2 жыл бұрын
Thank you really it was a good one ..
@webcifar
@webcifar 2 жыл бұрын
Glad you liked it!
@simond.7448
@simond.7448 Жыл бұрын
Thank you very much for this quick guide! It's awesome.
@photoinshot1355
@photoinshot1355 2 жыл бұрын
Excellent video, brilliant tutor, he explains things really well, clear well presented video, thanks!
@nimi_nomo
@nimi_nomo Жыл бұрын
Thanks so much. Helped a lot
@alphamx13
@alphamx13 10 ай бұрын
Great tutorial, thank you!
@kese1135
@kese1135 3 жыл бұрын
Thank you so much! You're the best!
@webcifar
@webcifar 3 жыл бұрын
You are welcome ❤️
@abdulraffy5398
@abdulraffy5398 Жыл бұрын
Nailed It!
@alexkelso1649
@alexkelso1649 3 жыл бұрын
thanks so much legend. Learned so much watching this.
@guilhermehammes1516
@guilhermehammes1516 3 жыл бұрын
simple and functional! thanks for the great video
@webcifar
@webcifar 3 жыл бұрын
Thanks
@havefun5519
@havefun5519 11 ай бұрын
Thanks, this is what I want
@noahdwhitney
@noahdwhitney 11 ай бұрын
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.
@istiakahammad7074
@istiakahammad7074 3 жыл бұрын
Finally i got it. Thanks
@tinghuang3218
@tinghuang3218 2 жыл бұрын
Great tutorial! This is perfect and helps me a lot. Thank you so much👍
@romuloalves9349
@romuloalves9349 3 жыл бұрын
Ótimo vídeo parabéns 👏.
@webcifar
@webcifar 3 жыл бұрын
Obrigado
@andreydario26
@andreydario26 3 жыл бұрын
puta video
@kennyakins3536
@kennyakins3536 3 жыл бұрын
This really helped a lot 👏
@webcifar
@webcifar 3 жыл бұрын
Glad it was helpful.
@chaipiyo
@chaipiyo 3 жыл бұрын
thank you so much brother .. very well explained
@lanhphalla1623
@lanhphalla1623 Жыл бұрын
Very good video. Can you create the video of this in small screen and move navbar by base on scroll?
@thanhannguyen2565
@thanhannguyen2565 2 жыл бұрын
It is extremely easy to understand.
@selsen9011
@selsen9011 Жыл бұрын
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?
@ankitkumarravidas6062
@ankitkumarravidas6062 2 жыл бұрын
yu are my life save bro thanks
@mwmersal
@mwmersal 2 жыл бұрын
Wooooow! this was unbelievably helpful mate. Thanks ^^
@webcifar
@webcifar 2 жыл бұрын
Glad to hear it!
@richardshaju
@richardshaju Жыл бұрын
Thank you so much 💝🥰
@patricioscida3949
@patricioscida3949 3 жыл бұрын
Great video, thank you so much.
@webcifar
@webcifar 3 жыл бұрын
You're very welcome!
@user-gw3yd8ev6p
@user-gw3yd8ev6p 2 жыл бұрын
Thanks for tutorial, it's very useful!
@raomudasir4509
@raomudasir4509 3 жыл бұрын
really awesome bro
@ogunkayodeoluwaseun9348
@ogunkayodeoluwaseun9348 2 жыл бұрын
What would happen if the nav li's had multiple sub-links ??? @WEB CIFAR
@tszpang9917
@tszpang9917 3 жыл бұрын
Thanks for the tutorial! Worked for my project :D
@webcifar
@webcifar 3 жыл бұрын
Glad it helped!
@liluo7790
@liluo7790 3 жыл бұрын
thank you so much ! thank you so much man
@webcifar
@webcifar 3 жыл бұрын
You're welcome!
@valeriyadolya8412
@valeriyadolya8412 3 жыл бұрын
Thank you very much, it helped me a lot!
@guxsta3217
@guxsta3217 2 жыл бұрын
Thank you so much!! Amazing video
@senju31
@senju31 2 жыл бұрын
I'm not seeing the footer in console.log. I see the home and about section but not the footer.
@imranhossainbpp
@imranhossainbpp 2 жыл бұрын
What if i want to add class in the nav while scrolling in a particular section ? Love from @Bangladesh
@ThisIsAhn
@ThisIsAhn 3 жыл бұрын
ধন্যবাদ ভাই
@sandeepsv3514
@sandeepsv3514 3 жыл бұрын
thanks thank you so much for the video it means a lot
@webcifar
@webcifar 3 жыл бұрын
Glad it helped
@ryukagai
@ryukagai 3 жыл бұрын
Exactly what I needed! Thank you :)
@webcifar
@webcifar 3 жыл бұрын
Glad it helped!
@selah_2215
@selah_2215 2 жыл бұрын
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 🙏
@webcifar
@webcifar 2 жыл бұрын
Glad it helped!
@ujjalzaman2722
@ujjalzaman2722 2 жыл бұрын
thank you so much for this one.
@webcifar
@webcifar 2 жыл бұрын
You're very welcome!
@paalaleksander
@paalaleksander 2 жыл бұрын
Thanks for this! Helped me a lot!
@webcifar
@webcifar 2 жыл бұрын
Glad it helped!
@jmcoxD
@jmcoxD Жыл бұрын
Excellent tutorial!
@shaaa00
@shaaa00 3 жыл бұрын
Thank you for sharing this tutorial, it really helped me
@webcifar
@webcifar 3 жыл бұрын
Glad to hear that!
@ankitraj5ar
@ankitraj5ar 3 жыл бұрын
very useful !!!!!!
@nadirmohamed8274
@nadirmohamed8274 3 жыл бұрын
You are the best bro
@webcifar
@webcifar 3 жыл бұрын
Thanks
@SamFourieOfficial
@SamFourieOfficial 2 жыл бұрын
My sections variable just has an empty list, so it does not pick up the sections.
@thangphan6047
@thangphan6047 2 жыл бұрын
Thank you so much :)
@gabrielfono844
@gabrielfono844 2 жыл бұрын
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
@webcifar
@webcifar 2 жыл бұрын
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.
@gabrielfono844
@gabrielfono844 2 жыл бұрын
@@webcifar thanks a lot 🙏
@__-qp9dl
@__-qp9dl 3 жыл бұрын
당신은 천재입니다. 감사합니다 !
@giovannimichel5506
@giovannimichel5506 2 жыл бұрын
Thank you for the intel
@sairaghava6111
@sairaghava6111 3 жыл бұрын
This implementation is breaking when I change the screen resolution, can you help here
@_4zad
@_4zad 2 жыл бұрын
Great vid, learned a lot!
@dustinbest1326
@dustinbest1326 2 жыл бұрын
Nice video! Thank you!
@siawonderswhy
@siawonderswhy 3 жыл бұрын
very helpful thank you
@webcifar
@webcifar 3 жыл бұрын
Glad it was helpful!
@Rystaal
@Rystaal 2 жыл бұрын
Don't work for me if section's height is in %... any advice to fix this issue?
@shas3626
@shas3626 2 жыл бұрын
Great video..had a question i am getting my section.OffsetTop as undefined.Can you help me with this?
@duvvadasaibhargav9879
@duvvadasaibhargav9879 2 жыл бұрын
Thanks for your tutorial learned a lot
@webcifar
@webcifar 2 жыл бұрын
Glad to hear that!
@harshilparmar9076
@harshilparmar9076 2 жыл бұрын
Thanks bro!!
@vishnuk9628
@vishnuk9628 2 жыл бұрын
how to keep the selected nav color the same even after refreshing the page
@dibanpitchaimuthu9336
@dibanpitchaimuthu9336 3 жыл бұрын
Great vid, just one error I noticed you forgotten 's' at 10:04 for transition
@LordzChilight
@LordzChilight 3 жыл бұрын
thank you, learn a lot :D 🙏
@alamineuropeanit583
@alamineuropeanit583 3 жыл бұрын
thanks. I like this tips
@ranadebnath5421
@ranadebnath5421 3 жыл бұрын
thanku so much bhai ...
@webcifar
@webcifar 3 жыл бұрын
Welcome Bhai ♥
@eddi3ms
@eddi3ms 3 жыл бұрын
very helpfull, thanks alot !!
@webnirbhar785
@webnirbhar785 2 жыл бұрын
How to open collapse data when scroll down in js Please help
@a.j9157
@a.j9157 3 жыл бұрын
Great video man keep up !
@webcifar
@webcifar 3 жыл бұрын
Thanks, you too!
@victory_lucky
@victory_lucky 3 жыл бұрын
nice, but please zoom in a little bit when recording, watching on mobile is quite difficult.
@webcifar
@webcifar 3 жыл бұрын
Noted. ❤
@tiendang5149
@tiendang5149 2 жыл бұрын
Very good , thank you!
@webcifar
@webcifar 2 жыл бұрын
Our pleasure!
@MohamedMedhat-ic5ng
@MohamedMedhat-ic5ng 3 жыл бұрын
thank you
@ahmadyamout6867
@ahmadyamout6867 2 жыл бұрын
Hello dear .Your code is not working because Pageyoffset is deprecated what is it's alternative please ?
@nadirmemmedov6071
@nadirmemmedov6071 3 жыл бұрын
good
@webcifar
@webcifar 3 жыл бұрын
Thanks
@MuhammadRizky-ub3oy
@MuhammadRizky-ub3oy Жыл бұрын
why is my home offsetTop returning 0?
@osman1110
@osman1110 2 жыл бұрын
hi how would you make it diff colours for each section?
@samarjamil3053
@samarjamil3053 3 жыл бұрын
Awesome Bro! ❤️
@webcifar
@webcifar 3 жыл бұрын
Thanks 🔥
@tomo_3883
@tomo_3883 2 жыл бұрын
Vsc theme?
@PreejalRatnaSilakar
@PreejalRatnaSilakar 2 жыл бұрын
helpful
@webcifar
@webcifar 2 жыл бұрын
Glad it helped
@omarakki705
@omarakki705 3 жыл бұрын
Thank you my brother
@webcifar
@webcifar 3 жыл бұрын
You are welcome
@omarakki705
@omarakki705 3 жыл бұрын
@@webcifar do you have a tutorial in javascript
@entertainmenthut8896
@entertainmenthut8896 2 жыл бұрын
Your tutorial does not work for me. I am using sublime 3.
@TommyTips
@TommyTips 3 жыл бұрын
It's cool ;)
@webcifar
@webcifar 3 жыл бұрын
🤟
@AzulCieloBlue
@AzulCieloBlue 3 жыл бұрын
When I scroll to the bottom the last section is not beign detected. help please! Cool and really helpful video btw
@mariyanesvyetaylo6264
@mariyanesvyetaylo6264 2 жыл бұрын
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 >_>
@Sebeklis
@Sebeklis 3 жыл бұрын
There are tons of problems with routing etc.
@zayednation3692
@zayednation3692 Жыл бұрын
bro, can u do it for react js?
@hugoshaco8149
@hugoshaco8149 3 жыл бұрын
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
@senju31
@senju31 2 жыл бұрын
There's a KZbinr by the name of Bedimcode that implemented this feature in this video kzbin.info/www/bejne/bJTMlZWLfbONiLM 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 KZbin video on it , explaining how Bedimcode made his own work
@aminzorriyeh2782
@aminzorriyeh2782 3 жыл бұрын
how can i get this cod
@harshjha271
@harshjha271 2 жыл бұрын
Please explain properly i did'nt understand the logic in (if condtion) if anyone understand please explain this logic to me
@r18570
@r18570 Жыл бұрын
thank you bro
@omarfarouk2080
@omarfarouk2080 3 жыл бұрын
Thank you bro!
The problems with viewport units
13:23
Kevin Powell
Рет қаралды 360 М.
Smooth Page Transitions With Javascript Tutorial
33:41
developedbyed
Рет қаралды 870 М.
This Simple Trick Makes Your Website 83% Better Looking
10:57
Web Dev Simplified
Рет қаралды 389 М.
Tic Tac Toe with Vanilla JavaScript
50:18
WEB CIFAR
Рет қаралды 5 М.
Show Active Nav Link with JavaScript
6:50
Coding in Public
Рет қаралды 17 М.
Landing Page With Smooth Scroll - 3 Options
22:43
Traversy Media
Рет қаралды 287 М.
Using CSS custom properties like this is a waste
16:12
Kevin Powell
Рет қаралды 169 М.
CSS Tips And Tricks I Wish I Knew Before
12:12
Lama Dev
Рет қаралды 474 М.