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

  • Home
  • SEARCH
  • 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 3978972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:06:46+00:00 2026-05-20T05:06:46+00:00

For a site I’m making for myself and a friend, I have a div

  • 0

For a site I’m making for myself and a friend, I have a div container/wrapper with 2 other divs within it: one occupies the left half and has a black background and the other occupies the right with a white background. Essentially, this lets me get a split colored background. Each div holds half of a logo. Here’s the page, temporarily hosted so you guys can see it.

http://djsbydesign.com/tempsite/index.htm

At any rate, I’d like to have links on the left and right hand sides of the page that, on click, cause their respective divs to expand from 50% to 100%. I have a few ideas, but am not sure entirely how to go about doing this (I’m rather new to javascript). The first would be to have the expanding div’s z-index set to something higher than the non-expanding one, and then have it expand (somehow), and the other is to have the expanding div expand to 100% while the other shrinks to 0% at an equal rate.

The bottom line is, I have no idea how to go about doing this. I don’t mind using mootools or jQuery, for the record.

  • 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-05-20T05:06:47+00:00Added an answer on May 20, 2026 at 5:06 am

    The following seems to work:

    $('#left-bg, #right-bg').click(
        function(){
            $(this).animate({'width': '100%'},600).siblings().animate({'width':'0'},600);
        });
    

    Albeit I’m not sure how you’d plan to bring back the the ‘other’ div.

    JS Fiddle demo.


    Edited to add a button (via jQuery) that allows both divs to be reverted to original dimensions:

    $('#left-bg, #right-bg').click(
        function(){
            $(this).animate({'width': '100%'},600).siblings().animate({'width':'0'},600);
            $('<button class="show">Show all</button>')
                .appendTo('#wrapper');
        });
    
    $('.show').live('click',
                    function(){
                        $('#left-bg').animate(
                            {
                                'width': '50%'
                            },600);
                        $('#right-bg').animate(
                            {
                                'width': '50%'
                            },600);
                        $(this).remove();
                    });
    

    Updated JS Fiddle.


    Edited to address the question left by OP in the comments:

    is there a way to have a page redirect after the animation completes?

    Yep, just add the line window.location.href = "http://path.to.url.com/";

    $('#left-bg, #right-bg').click(
        function(){
            $(this).animate({'width': '100%'},600).siblings().animate({'width':'0'},600);
            $('<button class="show">Show all</button>')
                .appendTo('#wrapper');
            window.location.href = "http://www.google.com/" // <-- this line redirects.
        });
    
    $('.show').live('click',
                    function(){
                        $('#left-bg').animate(
                            {
                                'width': '50%'
                            },600);
                        $('#right-bg').animate(
                            {
                                'width': '50%'
                            },600);
                        $(this).remove();
                    });
    

    Updated JS Fiddle.


    Edited in response to bug report (in comments):

    The one other bug (easy fix) is that any time you click on either of the divs, it creates a new button. So say you clicked on the left half, and it expanded and filled the page, etc., and then you clicked on it again (it being anywhere on the page now). It would attempt to add a second button.

    To prevent a second button being added to the div just add an if:

    $('#left-bg, #right-bg').click(
        function(){
            if (!$('.show').length) {
                $(this).animate({'width': '100%'},600).siblings().animate({'width':'0'},600);
                $('<button class="show">Show all</button>')
                    .appendTo('#wrapper');
                window.location.href = "http://www.google.com/" // <-- this line redirects.
            }
        });
    

    Which, will only append a button, or indeed animate the divs, so long as the $('.show') selector returns no matches.

    However if you’re also redirecting to another page by clicking the button it shouldn’t be an issue anyway, since none of the jQuery on the original page will exectute/be able to access the page to which the user is redirected (unless it’s a page on your own domain, and you’ve explicitly chosen to add the same button).

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

Sidebar

Related Questions

My site has three columns. I have two fields within a form that need
Site in question: http://www.blues-n-brews.com/paypal_receipt.php?tx=17G30980M69737722 I have this: <div id=print_special style=width: 1050px; zoom: 0.8; margin:
Site is Located @ beattrainsoundsystem.com/home I'm using serialScroll to animate a number of divs
Site navigation html: <div class=main_nav> <div><a href=home/>Home</a></div> <div><a href=company/>Company</a></div> <div class=active><a href=franchise/>Franchise</a></div> </div> When
I have a French site that I want to parse, but am running into
My site currently implements custom 404 pages which we have mapped in IIS. So
My site supports exporting data in a few ways, and one way i via
my site is hosted at IIS7.5 i have a controller action as below [HttpPost]
My site is in VB using VS 2010, and my z-index property I have
(Actual site names have been changed) I installed drupal on elephantboarding.com, and it is

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.