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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:41:46+00:00 2026-06-01T02:41:46+00:00

I have two div containers with content in them and two buttons outside the

  • 0

I have two div containers with content in them and two buttons outside the container like so:

<div id="containers">
    <div id="container_1">
        awesome container 1 content
    </div>
    <div id="container_2">
        awesome container 2 content
    </div>
</div>

<div id="container_1_button">
    Click me to open container 1
</div>
<div id="container_2_button">
    Click me to open container 2
</div>

I need to be able to animate width and left: to give the effect of the content sliding from the left when clicked. But only one can be open at a time. psuedo code would be: IE: if Container 1 width > 0 set width:0, set left:0 and the same for container 2. So that way if someone clicks on button 2 while container 1 is open it collapses container 1 and then opens container 2 and vice versa.

I have achieve the animation of the width/left pos on one element by using the following jquery:

//the Jquery collapsible left hand sidebarfor mapit
$('#map_sidebar_button').toggle(function(){
    collapseSidebarLeft();
    $('#sidebar_left_map').animate({width:0}, 'fast');
    $('.button_container').animate({left:0}, 'fast');
    $('#map_sidebar_button').removeClass('sidebar_left_button_toggle');
},function(){
    $('#sidebar_left_map').animate({width:260}, 'fast');
    $('.button_container').animate({left:260}, 'fast');
        // add a class to change the background coloring and border of the button
    $('#map_sidebar_button').addClass('sidebar_left_button_toggle');
});

You can see an example of the site that i need this implemented on here:
http://demo.mapitusa.com the left sidebar buttons..

  • 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-01T02:41:48+00:00Added an answer on June 1, 2026 at 2:41 am

    My approach would be to use the .each() method and bind a (single) click to each button with the same class, and depending on which one you clicked (based on its index) then select what awesome container to display.

    In this scenario, both awesome containers would have the same class too and will be hidden from visibility using a negative margin of the same value of their width, why? because in this way they won’t show the weird effect produced while animating the width (the elements inside the container will look like floating and arranging themselves during the animation) … so using this html:

    <div id="containers">
     <div id="container_1" class="awesome">awesome container 1 content</div>
     <div id="container_1_button" class="buttonsContainer"><a class="button" href="javascript:;">open 1</a></div>
     <div class="clear"></div><!--used in my example to separate floating containers-->
     <div id="container_2" class="awesome">awesome container 2 content</div>
     <div id="container_2_button" class="buttonsContainer"><a class="button" href="javascript:;">open 2</a></div>
    </div>
    

    the css for both containers and parent

    #containers {
     position: relative;
    }
    #containers .awesome {
     width: 300px; /* or whatever */
     margin-left: -300px; /* negative value of the width */
     overflow: hidden;
     float: left; /* to illustrate my example */
     display: block; /* if needed */
     /* etc other container properties */
    }
    

    then the jQuery where we assign a single click to the same selector (the shared class of both buttons)

    $(document).ready(function(){
     $(".button").each(function(i){
      var selector = $(this); // useful to refer to 'this' inside of any nested function
      selector.on("click", function(){
       if($(".awesome").eq(i).hasClass('visible')){
        $(".awesome").eq(i).animate({'marginLeft':-300},{ queue:false, duration: 200}).removeClass('visible');
       } else {
        // collapse all if any
        $(".awesome").animate({'marginLeft': -300},{ queue:false, duration:200, complete: function(){
          // remove to all the class "visible" if any
          $(".awesome")
           .removeClass('visible')
           // animate the corresponding (i) container and add class="visible"
           .eq(i).animate({'marginLeft':0},{ queue:false, duration:600})
           .addClass('visible');
         } // complete
        }); // animate
       } // if else
      }); //on
     }); //each
    }); //ready
    

    Notice that we use the complete callback option of .animate() so the next animation will be executed until the first one has been completed, in this case the second container will show up only until the first one collapses.

    You can see it working here for better understanding of the effect.

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

Sidebar

Related Questions

I have a container div that holds two internal divs; both should take 100%
I have two divs. I would like to move/populate the text from div id
On my page I have one navigation menu and two content containers. The content
I have two div's in a container div, one floating left, one floating right.
I have two <div> , one nested into the other defined like this: <div
I have a main div which contains two divs. One for main content and
I have a two column layout: <html> <head></head> <body> <div id=container> <div id=header></div> <div
I have a content div, that has a header div, which contains two other
I have two div elements that are twins (i.e. their dimensions and contents are
The scenario is I have two div s: one is where I select items

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.