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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:11:52+00:00 2026-06-07T23:11:52+00:00

New to coding, please help me out. I have a sliding code for a

  • 0

New to coding, please help me out. I have a sliding code for a vertical nav. When the user hovers over the nav, it slides out to the right. I want it to stay active once the user clicks on the nav. How do I go about doing that? Here is a link to a visiual

http://edgecastcdn.net/00009B//TEMP/NAV/index.html

in return for you help, here is a joke you guys might enjoy (if you haven’t heard of it already)

A wife asks her husband, a computer programmer; “Could you please go
to the store for me and buy one carton of milk, and if they have eggs,
get 6!”

A short time later the husband comes back with 6 cartons of milk.

The wife asks him, “Why the hell did you buy 6 cartons of milk?”

He replied, “They had eggs.”

Thanks guys, any help is appreciated! Here is the code. Let me know if you need the css too.

$(document).ready(function(){
    slide("#sliding-navigation", 30, 15, 150, .8);
});

function slide(navigation_id, pad_out, pad_in, time, multiplier){
// creates the target paths
var list_elements = navigation_id + " li.sliding-element";
var link_elements = list_elements + " a";

// initiates the timer used for the sliding animation
var timer = 0;

// creates the slide animation for all list elements 
$(list_elements).each(function(i)
{
    // margin left = - ([width of element] + [total vertical padding of element])
    $(this).css("margin-left","-180px");
    // updates timer
    timer = (timer*multiplier + time);
    $(this).animate({ marginLeft: "0" }, timer);
    $(this).animate({ marginLeft: "12px" }, timer);
    $(this).animate({ marginLeft: "0" }, timer);
});

// creates the hover-slide effect for all link elements         
$(link_elements).each(function(i)
{
    $(this).hover(
    function()
    {
        $(this).animate({ paddingLeft: pad_out }, 150);
    },      
    function()
    {
        $(this).animate({ paddingLeft: pad_in }, 150);
    });

});

}

Here is my CSS code (Updated with Douglas “active” code) Thanks!

body 
{
margin: 0;
padding: 0;
background: #1d1d1d;
font-family: "Lucida Grande", Verdana, sans-serif;
font-size: 100%;
}

h2  
{ 
color: #999;
margin-bottom: 0; 
margin-left:13px;
background:url(navigation.jpg) no-repeat;
height:40px;
}

h2 span
{
display: none;
}

p   navigation-block
{ 
color: #00b7e6; 
margin-top: .5em;
font-size: .75em;
padding-left:15px;  
}

#navigation-block {
position:relative;
}

#hide {
position:absolute;
top:30px;
left:-190px;
}

ul#sliding-navigation
{
list-style: none;
font-size: 0.75em;
margin: 30px 0;
padding: 0;
}

ul#sliding-navigation li.sliding-element h3,
ul#sliding-navigation li.sliding-element a
{
display: block;
width: 150px;
padding: 2px 18px;
margin: 0;
margin-bottom: 0px;
}

ul#sliding-navigation li.sliding-element h3
{
color: #fff;
background:#333333 url(heading_bg.jpg) repeat-y;
padding-top: 7px;
padding-bottom: 7px;
}

ul#sliding-navigation li.sliding-element a
{
color: #999;
background:#222 url(tab_bg.jpg) repeat-y;
border: 1px solid #1a1a1a;
text-decoration: none;
}

ul#sliding-navigation li.sliding-element a.selected { color: #cc0000; }
{
color: #FFF;
margin-top: 0.5em;
font-size: 10pt;
padding-left:15px;
font-weight: bolder;
}

ul#sliding-navigation li.sliding-element a:hover { color: #00b7e6; background:#2a2a2a; }
#navigation-block p {
color: #FFF;
margin-top: 0.5em;
font-size: 10pt;
padding-left:15px;
font-weight: bolder;
}


.active{
  padding-left:12px;
  /*Add whatever other styles you need */
}
  • 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-07T23:11:55+00:00Added an answer on June 7, 2026 at 11:11 pm

    It looks like your nav doesn’t actually change the page, just loads (or switches out) new content on the page.

    The easiest way to make this stay after a user clicks a link would be to add a class with the correct settings. For example:

    jQuery

    $(link_elements).hover(
      function()
      {
        $(this).animate({ paddingLeft: pad_out }, 150);
      },      
      function()
      {
        $(this).animate({ paddingLeft: pad_in }, 150);
      }
    ).click(function(){
      $(link_elements).removeClass("active");
      $(this).addClass("active");
    });
    

    CSS

    .active{
      padding-left:12px;
      /*Add whatever other styles you need */
    }
    

    EDIT: Added CSS


    EDIT:
    Okay, I see what I missed before – the jQuery is setting the padding inline which overrides the external CSS. You technically could use !important in the .active CSS, but I personally like this method more.

    Basically, I add the active class like before, but I only use it as a reference. When a user clicks a link, the active class is added. If a link has the active class, it does not animate on mouseout. When a not active class is clicked, active is removed from all other nav links, they’re all animated to their start point, and the new link is made active.

    This may be better explained with the relevant code:

    // creates the hover-slide effect for all link elements         
    $(link_elements).each(function(i) {
        $(this)
            .hover(
                function() {
                    $(this).animate({ paddingLeft: pad_out }, 150);
                }, function() {
                    if(!$(this).hasClass("active"))
                        $(this).animate({ paddingLeft: pad_in }, 150);
                })
            .click(
                function() {
                    $(link_elements).not($(this)).removeClass("active").animate({ paddingLeft: pad_in}, 150);
                    $(this).addClass("active");
                });
    }); // End `each` loop
    

    And the related jsFiddle: http://jsfiddle.net/eAaCn/
    (added console.log() and return false in the jsFiddle for testing only)

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

Sidebar

Related Questions

I'm relatively new to coding so please help me out here. The code will
We implemented new coding standards, which call for our private members to have a
I'm fairly new to coding in general, learning to code in rails, and feel
I am new to coding python. I am hoping to modify this code to
I am new to Javascript coding and have looked for this information in many
Im very new to all coding including jquery. I though this would have been
please help .... i have a tableview with a list of vehicle what i
A little new to Javascript coding, so please bear with me. I read through
I hope there is someone who can help me out here. I have found
Please have a look at my first JavaFX application code package helloworld; import javafx.application.*;

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.