This could be really obvious and I’m completely missing it.
I’ve searched for hours and can’t seem to find a way to, using jQuery, reveal a hidden div from the bottom up. What I am trying to achieve is exactly as in the following link, but in reverse: http://jqueryui.com/demos/show/
I can slide a div from the bottom to the top, but this reveals itself as it moves, rather than being ‘masked’ in.
Like I said, this could (should?) be really obvious and I’m not seeing it, but I’ve been looking for ages and can’t find a solution to this relatively simple problem.
Thanks,
Ronnie
The effect you’re looking for is a little tricky to achieve, but it can be done, even without a wrapper element.
The main issue here is that elements naturally render top-down, not bottom-up. Animating both the
topandheightCSS properties of a relatively-positioned element allows us to implement a slide-up effect, but the element will still render top-down:If we want to simulate bottom-up rendering, we have to modify the scrollTop property of the element during the animation, in order for its lower part to always remain in view:
We can use animate() with
scrollTop, but doing so in conjunction withtopandheightdid not work correctly in my tests (I suspectscrollTopis reset whentoporheightare modified in the first animation step, so it ends up stuck to0).To work around this, we can handle
scrollTopourselves through the optional step function we can pass toanimate(). This function is called with two arguments,nowandfx,nowbeing the current value of the animated property andfxbeing a wrapper object around useful information, like the element and property being animated.Since we always want
scrollTopto be the same astop, we only have to test iftopis being animated in ourstepfunction. If it is, we setscrollToptonow. This solution gives acceptable results, although it flickers a little too much for my taste (that might be an artifact of my browser, though).So, in summary, to implement that effect, we have to:
position: relative;so we can animate itstopproperty,topto the original height andheightto0,display: none;is applied),topto0andheightto the original height,scrollTopthe value oftopon each animation step.Resulting in the following code:
You can test it in this fiddle.