How to Create an Active Nav Link on Scroll using HTML CSS and Javascript | Active Menu Class

Поделиться
HTML-код
  • Опубликовано: 16 янв 2025

Комментарии • 60

  • @SilakhulMufid
    @SilakhulMufid Год назад +12

    I finally found what I was looking for.... Thanks dude

  • @DiogoScarmagnani
    @DiogoScarmagnani Год назад +8

    Your channel is a piece of cake! Thank you for too many things you're sharing with us, I'm learning a lot! My best regards from Brazil. 🇧🇷

    • @codehal
      @codehal  Год назад +1

      Glad to help 💚

    • @williamoliveira8123
      @williamoliveira8123 Год назад

      Que legal encontrar outros brasileiros que gostam desse canal.

  • @delmontee
    @delmontee Год назад +2

    Great article, thanks. If you want to have the URL hashtag update as you cycle through, add something like " linkid='X' " to each a href, then add an onclick event to each link, where the parent.location.hash changes to the whatever the linkid attribute is . If you want to then add that in to the url's page history, use window.history.pushState(..... then the user can navigate back to previous sections via the back button.

  • @coders-rabbi
    @coders-rabbi Год назад +1

    perfectly working. This is an amazing video.😘

  • @alinagrinmn
    @alinagrinmn Год назад +1

    Thank you for the great video! Have been looking for a right and smooth solution for a couple of days.

  • @surajramani5279
    @surajramani5279 Год назад +1

    it's a very helpfull for me....Thanks 👍

  • @atiqur-k3m
    @atiqur-k3m 10 месяцев назад

    Many many thanks brother❤❤❤❤❤❤

  • @souvik_745
    @souvik_745 8 месяцев назад

    It helped a lot. Thank you so much 😊

  • @solongdygaming4729
    @solongdygaming4729 Год назад

    You're very good at explaining

  • @excorific2205
    @excorific2205 Год назад

    Amazing work. Simple yet impactful and full of knowledge. Thank you so much I need to leave a comment expressing my gratitude.

    • @codehal
      @codehal  Год назад

      Thank you! That's absolutely fine

  • @youtubechannel548
    @youtubechannel548 10 месяцев назад +3

    Cool, but what if all sections are not 100vh? If all sections are 100vh it's easy, but what do you do if they are not?

  • @renzotomas3725
    @renzotomas3725 10 дней назад

    Very useful, thanks! I have a question, its 100% responsive?

  • @amitsevda4723
    @amitsevda4723 Год назад +3

    Amazing work❤❤❤

    • @codehal
      @codehal  Год назад +1

      Thank you 💚

  • @jaimecadenas8495
    @jaimecadenas8495 Год назад

    Muchas gracias, por compartir... comprendido

  • @allahmacedo1993
    @allahmacedo1993 Год назад

    Obrigado , me ajudou bastante .

  • @ICARO7
    @ICARO7 Год назад +2

    Muito boa a explicação 😊✌️ Deus abençoe!

  • @abdullahjama8404
    @abdullahjama8404 10 месяцев назад

    thanks appreciate the help.

  • @pgameverse
    @pgameverse Год назад +1

    Lovely song in starting

  • @DLXXXI
    @DLXXXI 9 месяцев назад

    Do i need to use section or can i use div to

  • @aman12988
    @aman12988 Год назад +3

    Brother, " *window.onscroll* " property is not working. I had to use " *window.addEventListener("scroll" , )* " instead to make it work..
    But I still couldn't figure out why * .onscroll* didn't work, can you please tell why it didn't work, has it gone deprecated or something, or any other issue..??

    • @zaindevs
      @zaindevs Год назад +1

      Yoe have to use window.scrollY ...

  • @argylleagen
    @argylleagen Год назад +1

    The logic starts @ 6:30

  • @SammerTime-o6e
    @SammerTime-o6e Месяц назад

    🔥🔥🔥🔥🔥🔥🔥

  • @ikiruu4333
    @ikiruu4333 9 месяцев назад +1

    @Codehal the onscroll and scrollY doesnt work...

  • @ritikmanta0028
    @ritikmanta0028 9 месяцев назад +1

    This was single page website but if we have multi page website how make active link in that case ???

    • @Garden_of_Words.
      @Garden_of_Words. 8 месяцев назад

      Pretty sure you can do:
      a:is(:link, :active, :visited).active { color: white; background-color: black;}

    • @taneees
      @taneees 6 месяцев назад

      Just apply the .html of that multi page in anchor tag

    • @शाकुन्तलम्
      @शाकुन्तलम् 6 месяцев назад

      I usually do it using the uselocation hook lol, but it's just a cheap workaround, if your website is veryyyy small orrr you can maybe use isActive (I remember it was used by me in my beginner coding days) there's some library for that in react
      Ps: I assumed you've used react here

  • @abhishekdubalgonde
    @abhishekdubalgonde Год назад

    😇cool thank you soooo much

  • @cezar5875
    @cezar5875 Год назад +1

    0:16 how to make this effect when double click on the text

    • @baazigar5
      @baazigar5 Год назад

      by pseudo element ===>
      ::selection{
      }

  • @reatasu
    @reatasu Год назад

    can I use this in my website?

  • @the_sahil_patil
    @the_sahil_patil Год назад

    Can we do this using php instead of js?

  • @sange7512
    @sange7512 Год назад

    This is what I find thanks

  • @rznxxnt
    @rznxxnt 6 месяцев назад +1

    Mine doesn't work at all with the scroll-behavior: smooth function, does anyone know why?

  • @MansiChovatiya
    @MansiChovatiya Год назад +2

    I wanted to express my sincere gratitude for the invaluable knowledge and insights I've gained from you. Your guidance has been instrumental in my growth, and I deeply appreciate the opportunity to learn from your expertise.🥳

  • @ayouby12
    @ayouby12 Год назад

    Thank you

  • @eothay
    @eothay Год назад

    Responsivo, responsive?

  • @maharshi5555
    @maharshi5555 Год назад

    If I put "top >= offset - 98 (height of header), then only it is perfectly working with complete scroll to the section...Any suggestion?

  • @Kau_Ram
    @Kau_Ram Год назад

    Lots of love bro

  • @milanigp
    @milanigp 8 месяцев назад

    This is great video works absolutely fine. But there is one more issue. When I click on the nav link, the page scrolls to top of the page, and my page is hiding under the navbar. So content of the page hides by header. How can we add the header offset so clicking on the nav link scrolls to just after the header? Can anyone have this problem and can suggest what we can do for this?

  • @WawanSetiawan-sh8kv
    @WawanSetiawan-sh8kv Год назад

    This amazing

  • @colommbiano
    @colommbiano 8 месяцев назад

    How can you do the same but using react?

  • @kenbadiola7283
    @kenbadiola7283 6 месяцев назад

    just do on the css do this for easy code
    *{
    scroll-behavior: smooth;
    }
    its done it works just like in the video

  • @mohamedel-gizawy5878
    @mohamedel-gizawy5878 3 месяца назад

    There is a wrong in classList.add('active') do anyone know the reason,please?

  • @Bunnyhorizons
    @Bunnyhorizons 8 месяцев назад

    How to put a text inside it broo if i put text its not inside

  • @शाकुन्तलम्
    @शाकुन्तलम् 6 месяцев назад

    Yo, I could see it working but the .active part is not really working ( I am using react), any solutions? I tried looking up and I feel the possible reason is the `.classList` being used. can anyone help me out??

  • @fahadbajwa614
    @fahadbajwa614 3 дня назад

    where is code??

  • @Light---Yagami
    @Light---Yagami Год назад

  • @vedad_1335
    @vedad_1335 10 месяцев назад

    I didnt apply java script and its stilll working hmm

  • @kira3821
    @kira3821 Год назад

    it works for the first 5 section, but it doesnt work on the last lmao

  • @omarkicmari1936
    @omarkicmari1936 8 дней назад

    Can somone send me the code pls

  • @MahanSingh-k2z
    @MahanSingh-k2z Год назад

    @aman12988
    @aman12988
    1 month ago
    Brother, " window.onscroll " property is not working

    • @zaindevs
      @zaindevs Год назад

      bro use window.scrollY property ... it works

    • @ikiruu4333
      @ikiruu4333 9 месяцев назад

      window.scrollY doesn't work either