I'd like the selected tab to stay rasied

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

So I have a navigation bar with an animation. When a user clicks on a navigation item, I want it to stay raised.

Here's the navigation bar:
http://xaetrex.net/voltecdesign/ctdrums/navbar.html

this is the javascript for the raise effect:
Code: [ Select ]
$(document).ready(function(){

$("li.navitem").hover(
function () {
    $(this).animate({
        top: "0px"
     }, 150 );
    $(this).animate({
        top: "10px"
     }, 50 );
},

function () {
    $(this).animate({
        top: "20px"
     }, 100 );
}
);
                        
});
  1. $(document).ready(function(){
  2. $("li.navitem").hover(
  3. function () {
  4.     $(this).animate({
  5.         top: "0px"
  6.      }, 150 );
  7.     $(this).animate({
  8.         top: "10px"
  9.      }, 50 );
  10. },
  11. function () {
  12.     $(this).animate({
  13.         top: "20px"
  14.      }, 100 );
  15. }
  16. );
  17.                         
  18. });

when a user clicks on a navbar item, I need it to stick at "top:10px;"

How would I implement this?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Instead of altering CSS properties, add and remove a classname that includes the properties.

When a page loads, the active tab should include that classname.

If you're using AJAX or something and your page is not refreshing, you can attach the hover listener to the click event as well, but within the click event you detach the hover event before reattaching it to the previously active tab.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

so...something like this? it's not working, but I'm wondering if I'm on the right track:
Code: [ Select ]
$("li.navitem").click(
function () {
    $("#menu > li").addClass("navitem");
    $("li.navitem").removeClass("selected");
    $(this).removeClass("navitem");
    $(this).addClass("selected");
}
);
  1. $("li.navitem").click(
  2. function () {
  3.     $("#menu > li").addClass("navitem");
  4.     $("li.navitem").removeClass("selected");
  5.     $(this).removeClass("navitem");
  6.     $(this).addClass("selected");
  7. }
  8. );

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 113 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.