I don't know if this applies to 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 shell to make sure that 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 am using #wrapper
white-space:nowrap; // Newer break whitespaces (break to the next line)
and
width:100%;
In #left, #right we use:
display:inline-block;
witch is first compatible with s> 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 events to both #right and #left
$(selector).hover(mouseOverHandler, mouseOutHandler);
...
$(this).parent().children().not(this)
We take the element in which the event is fired and find all its parents ( #wrapper ) childNodes: $(this).parent().children() Now we filter out everything that matches this using the jQuery not method. ( this = #left OR #right ) which is an element. Now we have #right -> #left and #left -> #right .
mouseOutHandler resets all #wrapper childNodes to 50%
Hope this leads you to the right path ...
EDIT:
If the duration of your animation ends with a chain / queue, you can use the stop method, which stops all active animations and clears the queue:
$(selector).stop().animate({ .... })