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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:37:51+00:00 2026-05-11T03:37:51+00:00

I’m trying to create a simple toggling sidebar using jquery, where it expands and

  • 0

I’m trying to create a simple toggling sidebar using jquery, where it expands and contracts when a button is pressed. The button also changes to another type of button when pressed. The sidebar will expand, but for some reason, it will not move back to it’s original position. You can see a copy of the javascript and html at http://www.jqueryhelp.com/viewtopic.php?p=4241#4241

Here is the working code, thanks Bendeway! 😀

$('.btn-slide').live('click', function(e){     e.preventDefault();     $('#sidebar').animate({opacity: 'show', left: 250}, 'slow');     $(this).toggleClass('btn-slide').toggleClass('active'); });   $('.active').live('click', function(e){     e.preventDefault();     $('#sidebar').animate({opacity: 'hide', left: 100}, 'slow');     $(this).toggleClass('btn-slide').toggleClass('active'); }); 
  • 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. 2026-05-11T03:37:52+00:00Added an answer on May 11, 2026 at 3:37 am

    try instead of right use left with a negative number. in addition I would recommend using preventDefault instead of returning false.

    $('.active').click(function(e){     e.preventDefault();     $('#sidebar').animate({opacity: 'hide', left: -250}, 'slow');     $(this).toggleClass('btn-slide'); });  

    Update

    Another piece i just noticed is that your attaching a click event to the .active button, when the document is ready, but there is no .active button when the document is ready that comes in after you change it. There are a couple options here.

    First is to use the new live feature of jquery 1.3

    $('.btn-slide').live('click', function(e){     e.preventDefault();     $('#sidebar').animate({opacity: 'hide', left: 250}, 'slow');     $(this).toggleClass('btn-slide').toggleClass('active'); });   $('.active').live('click', function(e){     e.preventDefault();     $('#sidebar').animate({opacity: 'hide', left: -250}, 'slow');     $(this).toggleClass('btn-slide').toggleClass('active'); });  

    The other option would be to have set the click event on a different modifier (eg. on the id, maybe).

    <span>News  <img src='img/overlay.png' id='sliderButton' class='btn-slide' alt='' /></span>      

    then use this to handle the click

    $('#sliderButton').click(function(e){    e.preventDefault();    $(this).is('.btn-slide').each(function() {    $('#sidebar').animate({opacity: 'show', left: 250}, 'slow');    });    $(this).is('.active').each(function() {    $('#sidebar').animate({opacity: 'hide', left: -250}, 'slow');    });   $(this).toggleClass('active').toggleClass('btn-slide');   });  

    or even more concise

    $('#sliderButton').click(function(e){    e.preventDefault();    var animationSettings = {opacity: 'show', left: 250};   if ($(this).hasClass('active') )   {     animationSettings = {opacity: 'hide', left: -250};   }     $('#sidebar').animate(animationSettings , 'slow');    $(this).toggleClass('active').toggleClass('btn-slide');   });  

    The final option that I can think of would be to set the click events after you change them, but I wouldn’t do that so I’m not going to supply a sample.

    Lastly, I would put in alert into your active callback and make sure that your active button event is actually firing.

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

Sidebar

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.