Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:38:19+00:00 2026-05-14T14:38:19+00:00

I have a menu: <ul class=menu-bottom> <li id=m1 class=active><a id=1 href=#><span>Link 1</span></a></li> <li id=m2><a

  • 0

I have a menu:

  <ul class="menu-bottom">
  <li id="m1" class="active"><a id="1" href="#"><span>Link 1</span></a></li>
   <li id="m2"><a id="2" href="#"><span>Link 2</span></a></li>
   <li id="m3"><a id="3" href="#"><span>Link 3</span></a></li>
</ul>

I want that depending of browser’s scroller position, the “active” class goes the correct < li > element.

This is how I see it :

     if ($(document).height() == 500) {
$('#m1').parent().addClass('active').
siblings().removeClass('active');
}

     if ($(document).height() == 1000) {
$('#m2').parent().addClass('active').
siblings().removeClass('active');
}

     if ($(document).height() == 1500) {
$('#m2').parent().addClass('active').
siblings().removeClass('active');
} 

I am not very familiar with jQuery Dimensions properties so this code doesn’t make much sense, but I hope you get the idea.

If someone could tell me how to make this work, it would be really cool.

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:38:20+00:00Added an answer on May 14, 2026 at 2:38 pm

    It’s not entirely clear what it is you’re trying to do, but I’ll take a stab at it. To get the amount the window has scrolled vertically you’ll want to use jQuery’s scrollTop() function. The height() function gives you the height in pixels of the element upon which it is called, so it won’t be very useful if the scroll value is what you want. Something like this might be closer to what you need:

    // bind a function to the window's scroll event, this will update
    // the 'active' class every time the user scrolls the window
    $(window).scroll(function() {    
        // find the li with class 'active' and remove it
        $("ul.menu-bottom li.active").removeClass("active");
        // get the amount the window has scrolled
        var scroll = $(window).scrollTop();
        // add the 'active' class to the correct li based on the scroll amount
        if (scroll <= 500) {
            $("#m1").addClass("active");
        }
        else if (scroll <= 1000) {
            $("#m2").addClass("active");
        }
        else {
            $("#m3").addClass("active");
        }
    }
    

    Even if the above isn’t on the right track, there are a couple other things to note that might help. The lines such as $('#m1').parent().addClass('active').siblings().removeClass('active'); are likely not doing what you expect. Rather than adding the ‘active’ class to the li and then removing it from the li’s siblings, it’s actually adding the class to the parent ul and removing it from the ul’s siblings. Try removing .parent() from each line and that should work.

    Also, since you are using == in your if conditions, the class will be added only when the value is exactly 500 or 1000 etc. which I doubt is what you intend. That’s why in the code above I changed it to be <= for the conditional statements.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have a menu div that I want to slide down so it's always
I have a menu of product brands that I want to split over 4
I have a table that looks like the following. <tr> <td>Link Name</td> <td><a href=#
I have vertical submenu as under: <div id=dropdown_menu class=menu> <ul> <li> <a>First Link</a></li> <li>
I have a menu with an animation going on, but I want to disable
I have a (derived) Menu control, that displays a rather large list of items
I have a jquery menu that has so many entries that it extends further
I have an slider that ads an class (.current-item) to each tab that is
I have a menu running off of a sitemap which one of the SiteMapNode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.