views:

43

answers:

3

Hello,

I've been trying to use the slideDown() effect for a website I'm working on, but I'm having difficulty getting the effect I want. Here's a sample showing what I want to accomplish.

<div>
    blahblahblahblah

    <span id="span_more" style="display:none">
        blahblahblah
    </span> 

    <a class="link_more" id="more">More&hellip;</a></div>
</div>

Basically, when "More..." is clicked, I want the text that's currently hidden to appear using a sliding effect while staying inline with the end of the visible text. This doesn't seem possible with slideDown() because it is changing display to block.

Thank you very much.

A: 

Unfortunately, this is essentially impossible. jQuery's animation relies upon the element having height and width. Inline elements do not have these dimensions set or settable, so animations (whether using animate or slideUp) must make them block-level elements.

fadeIn does work, and may be a useful alternative.

lonesomeday
But presumably you could achieve this by displaying the `inline` elements as `inline-block` (this should even work on IE6, with a valid doctype)?
David Thomas
@David I can't make this work, even in FF3.6! I don't think jQuery likes animating `inline-block`...
lonesomeday
It may well have issues with the basic `inline` portion, I didn't *try* it before making my presumption, it's just that I assumed jQuery's need for `width` and `height` could be satisfied by `display: inline-block` was all. Ah, my wilful naïveté... =)
David Thomas
As a workaround, would it be possible to start an animation at a predefined height value within the element? This would let me replace the text snippet with the whole text, then start the animation at the right place(where the snippet finishes).
Patrice Paquette
A: 

I've had that problem before. At that time it seemed not possible to change the jQuery behaviour, and I ran into problems while writing a routine that would do the same with inline blocks. So, I switched to just using display: block elements with float: left to keep them in one line.

<div>
    <div style="display: block; float: left;">blahblahblahblah</div>

    <div id="span_more" style="display: none; float: left;">
        blahblahblah
    </div> 

    <a style="display: block; float: left;" class="link_more" id="more">More&hellip;</a></div>
</div>
littlegreen
A: 

You'll need to wrap your text that always shows in a span or div that floats left, have the "additional" text float left as well, and have your link clear: both;, but this structure will make a simple .slideDown() work:

<div>
    <span style="float: left;">blahblahblahblah</span>

    <span id="span_more" style="display: none; float: left;">
        blahblahblah
    </span>

<div style="clear: both;"><a class="link_more" id="more">More&hellip;</a></div>
</div>

Here's a demo showing this in action: http://jsfiddle.net/7yqMr/

Ender
Thanks for your answer. This seemed like a good solution but it doesn't work with longer text.
Patrice Paquette