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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:10:48+00:00 2026-05-26T14:10:48+00:00

I have two divs that have 50% width each. I want to make it

  • 0

I have two divs that have 50% width each. I want to make it so that the the hovered div expands to 70% and the other reduces to 30%. And when the mouse moves out, they both return to 50% each. I wrote a script but it doesn’t give the right results. The widths are fluid so they need to adjust to all window sizes. how Can I make this work right?

I didn’t write the mouseout function yet as the mouseover doesn’t function correctly.

Here’s how it works now:
http://jsfiddle.net/kYZyp/

Here’s my code:

<div id="left" class="content_left"></div>
<div id="right" class="content_right"></div>

Here’s my css for the div’s

.content_left {
    width:50%;
    top:0px;
    left:0px;
    bottom:0px;
    background:url(wedding.jpg) left center no-repeat;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
    filter: alpha(opacity=90);
    -moz-opacity:0.9;
    -khtml-opacity: 0.9;
    opacity: 0.9;
}

.content_right {
    width:50%;
    top:0px;
    right:0px;
    bottom:0px;
    background:url(events.jpg) right center no-repeat;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
    filter: alpha(opacity=90);
    -moz-opacity:0.9;
    -khtml-opacity: 0.9;
    opacity: 0.9;
}

And i’m using this script:

<script>
$("#left").mouseover(function(){
  $("#left").animate({
    width: "70%",
    opacity: 1
  }, 1500 );
  $("#right").animate({
    width: "30%"
  }, 1500 );
});

$("#right").mouseover(function(){
  $("#right").animate({
    width: "70%",
    opacity: 1
  }, 1500 );
  $("#left").animate({
    width: "30%"
  }, 1500 );
});

</script>

And including this jQuery file:

<script src="http://code.jquery.com/jquery-1.7rc2.js"></script>
  • 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-26T14:10:49+00:00Added an answer on May 26, 2026 at 2:10 pm

    Doesn’t know if this suites you: http://jsfiddle.net/yCY9y/3/

    DOM:

    <div id="wrapper">
        <div id="left" class="content_left">LEFT</div><div id="right" class="content_right">RIGHT</div>
    </div>
    

    I use the wrapper to be sure we never break the RIGHT to the next line.

    CSS:

    #wrapper {
        width:100%;
        overflow:hidden;
        white-space:nowrap;
    }
    #left, #right {
        display:inline-block;
        width: 50%;
    }
    #left {
        background:red;
    }
    #right {
        background:yellow;
    }
    

    I use on #wrapper

    white-space:nowrap; // Newer break whitespaces (break to the next line)
    

    and

    width:100%;
    

    On #left, #right we use:

    display:inline-block;
    

    witch is first compatible with >IE6. (hopes this is not a problem).

    JS:

    $("#left, #right").each(function() {
        $(this).data("standardWidth", $(this).width());
    });
    
    $("#left, #right").hover(function() {
        $(this).animate({
            width: "70%"
        }, 300 );
        $(this).parent().children().not(this).animate({
            width: "30%"
        }, 300 );
    }, function() {
        $(this).parent().children().each(function() {
            $(this).animate({
                width: $(this).data("standardWidth")
            }, 300 );
        });
    });
    

    First i Bind the same mouseover and mouseout event on both #right and #left

    $(selector).hover(mouseOverHandler, mouseOutHandler);
    

    …

    $(this).parent().children().not(this)
    

    We take the element the event is fired throw and finds all it’s parents (#wrapper) childNodes: $(this).parent().children() Now we filter out everything matching this using jQuery’s not method. (this = #left OR #right) witch is the element. Now we have #right -> #left and #left -> #right.

    The mouseOutHandler resets all of #wrapper childNodes’s width to 50%

    Hopes this leads you the right way…

    EDIT:

    If you are expiring your animation to chain / queue up use can use the stop method witch stop all active animations and clears the queue:

    $(selector).stop().animate({
        ....
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two div's and I want to show them next to each other.
I have two divs floated left so that they appear next to each other.
I want to have 5 divs horizontally next to each other spanning the width
I have a container div that holds two internal divs; both should take 100%
I have two DIVs that I need to position exactly on top of each
I have two divs next to each other, one with float: right and the
I have two divs floating next to each other, with class name div1 and
I have two divs and two separate links that triggers slideDown and slideUp for
I have two divs. I would like to move/populate the text from div id
i have two divs one floated to the left and the other to the

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.