Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animation slideLeft without text wrapping

I would like to show / hide a paragraph of text using jQuery left to right.

I'm using

$('#text').animate({
     width: ['toggle', 'swing']
});

However I am seeing that the paragraph wraps as the animation is happening. And it looks ugly.

See this js fiddle for an example of the undesired effect.

How would you recommend getting the same effect but with no wrapping? (Like .slideUp() / slideDown())...

Thanks for any help

like image 465
Chris Avatar asked Nov 17 '11 10:11

Chris


2 Answers

You need to set overflow: hidden on the container, and then apply the animation to the container.

Updated fiddle with fix here

like image 112
Rory McCrossan Avatar answered Nov 11 '22 14:11

Rory McCrossan


Try this:

CSS:

#wrap{
 width:200px;   
    overflow: Hidden;
}
#text{
 width:200px;  
}

Script:

setTimeout(
function(){
    $('#wrap').animate( // Changed to slide the wrap instead of the #text
        {
            width: ['toggle', 'swing']
        })
    },
1000);

http://jsfiddle.net/RDsqy/2/

like image 20
Niels Avatar answered Nov 11 '22 13:11

Niels