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 7722737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:15:43+00:00 2026-06-01T04:15:43+00:00

Basically I have a single page site that scrolls when the user clicks on

  • 0

Basically I have a single page site that scrolls when the user clicks on the navigation menu.

<div id="mainnav">
<ul id="nav">

<li class="fadertwo"><a id="tst" onclick="CngClass(this);" href="index.html#abouttwo">About</a></li>

<li class="faderthree"><a id="sec"  onclick="CngClass(this);" href="index.html#second">Curriculum vitae</a></li>
<li class="faderfour"><a id="third" onclick="CngClass(this);" href="index.html#thirdtwo">contact</a></li>

</ul>



</div> <!-- end mainnav -->

Using jquery (which im totally new to) it adds a class when the user clicks on each link.
Basically it transitions the background position.

    .active {
background-position:bottom;
text-decoration:none;
 -webkit-transition: .3s linear;
       -moz-transition: .3s linear;
         -o-transition: .3s linear;
            transition: .3s linear;
}

Background is a 10px img repeating along the top.

#tst {background-image:url(../_images/whiteb.png);
background-repeat:repeat-x;
 -webkit-transition: .3s linear;
       -moz-transition: .3s linear;
         -o-transition: .3s linear;
            transition: .3s linear;

}


#sec {background-image:url(../_images/blackb.png);
background-repeat:repeat-x;
 -webkit-transition: .3s linear;
       -moz-transition: .3s linear;
         -o-transition: .3s linear;
            transition: .3s linear;

}

#third {background-image:url(../_images/greenb.png);
background-repeat:repeat-x; 
 -webkit-transition: .3s linear;
       -moz-transition: .3s linear;
         -o-transition: .3s linear;
            transition: .3s linear;}

Now the jquery magic –

<script type="text/javascript">

var Lst;

function CngClass(obj){
 if (typeof(obj)=='string') obj=document.getElementById(obj);
 if (Lst) Lst.className='';
 obj.className='active';
 Lst=obj;
}


</script>

It works great changing the background position in a really smooth way when the user clicks it, but of course doesn’t change based on the user scrolling the page naturally.
Now, I could set the body overflow to :hidden; and ‘fix’ that, but it’s a bit hacky and will limit the content area and overall site layout.

What I’d like to do is use jquery to add the class .active to the a tag based on scroll position so it changes anyway.

I’ve looked around for hours and tried different things but my (lackof) knowledge of jquery limits me somewhat it implementing anything I find effectively.

Can anyone offer any solution?

  • 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-06-01T04:15:45+00:00Added an answer on June 1, 2026 at 4:15 am

    Have a look at scrollspy

    http://twitter.github.com/bootstrap/javascript.html#scrollspy

    or

    https://github.com/sxalexander/jquery-scrollspy

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

Sidebar

Related Questions

Basically I have a single page on my site that I want any php
I have a web site that gets a new page every couple weeks, and
I have a single page that I need to on occasion asynchronously check the
I have a large, dynamically generated, single page website that heavily relies on javascript.
I basically have a page which shows a processing screen which has been flushed
I basically have 7 select statements that I need to have the results output
Basically, I'm wondering if any of you have put together a for-profit e-commerce site
Sorry for this question. Basically I have a page where I have it automatically
Ok, so basically I have a jspf template file with a backing FragmentBean that
I have a form on a page that can filter a results table and

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.