Question

So when using the JQuery slideUp or slideDown functions, the container on which the function is called performs the slide, but the content stays put.

An Example

I would like the content to move with the container. If you slide left or right you can see the correct effect.

I experimented a bit with the various engines trying to find a solutions (as you can probably tell from the jsfiddle), but have not succeeded.

How can you make the content of a container slide up or down with the container when hiding or showing it? The solution must be applicable to a variable number of containers stacked on each other.

UPDATE:

Using Nando's answer, I made a working solution.

Was it helpful?

Solution

SlideUp or Slidedown only manipulates the height of elements. If you want to move the content inside that manipulated element, you need to create a custom animation.

Run an animation to outer, which manipulates the height and a second animation to inner, which manipulates the css top property.

<div class="outer">
  <div class="inner">

  </div>
</div>

Otherwise you can set the position of inner absolute to the bottom of outer something like this.

.outer {
    position:relative;
    height:200px;
    display:none;
    width:300px;
    overflow:hidden;
}

.outer > .inner {
    position:absolute;
    width:300px;
    height:200px;
    background-color:red;
    bottom:0px;
}

<div class="outer">
    <div class="inner">
        Content<br />Content<br />Content
    </div>
</div>

OTHER TIPS

Wrap all your content inside one div and set it to position:absolute.

single_alert_update("<div style='position:absolute; bottom:0px; width:55%; text-align:right;'>Notice " + (++count)+"</div>");

Then set the position of #global-alerts .alert to relative this will do the trick.

The answer of Nando is very good, this is just an example on your code.

Fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top