views:

59

answers:

2

Hi, I have a simple problem but I am not sure how to solve it.

Basically I have some hidden content that, once expanded, requires a height of 99px. While collapsed the element holding it section#newsletter is set to be 65px in height.

LIVE EXAMPLE: http://dev.supply.net.nz/asap-finance-static/

On the click of a#signup_form the section#newsletter is expanded to 99px using the following jQuery:

$('#newsletter_form').hide(); // hide the initial form fields
$('#form_signup').click(function(event) {
    event.preventDefault(); // stop click
    // animate
    $('section#newsletter').animate({height: 99}, 400, function() {
        $('#newsletter_form').show(300);
    })
});

All this works great except for the fact that this element sits in a sticky footer so its initial height is used to position it.

Animating the height of this element causes scrollbars on the browser, because the 34px added are added to the bottom of the element, so my question:

How can I add these 34px to the top of the element so the height expands upwards into the body not downwards?

Thanks for reading, I look forward to your help and suggestions.

Jannis

+1  A: 

The answer to your question is the answer in this other StackOverflow post. http://stackoverflow.com/questions/1647462/jqueryanimate-conundrum

Dustin Laine
Thanks, I was able to work it out based on those examples.
Jannis
A: 

just to post the complete solution to my specific problem in case this may help others, here is the code:

JS:

$('your_trigger').click(function(event) { // click on the button to trigger animation
    event.preventDefault(); // stop click
    // animate
    function resizer () { 
        // run inside a function to execute all animations at the same time
        $('your_container').animate({marginTop: 0, height:99}, 400, function() {
            $('#newsletter_form').show(300); // this is just my content fading in
        });
        // this is the footer container (inside is your_container) 
        // & div.push (sticky footer component)
        $('footer,.push').animate({marginTop:0}, 400);
    };
    resizer(); // run
});

CSS: (this is the sticky footer i am using)

/* ================= */
/* = STICKY FOOTER = */
/* ================= */
html, body {
    height: 100%;
}
#wrap {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -135px; /* -full expanded height of the footer */
position: relative;
}
footer, .push {
height: 101px; /* height of this is equal to the collapsed elements height */
clear: both;
}
section#newsletter,footer {
    margin-top: 34px; 
    /* this is the difference between the expanded and the collapsed height */
}

So basically I am positioning my footer as I would normally with the full height of the TOTAL (after animation height) and then I push down the initial content via margin-top to compensate for the lesser value in height when the your_container is collapsed.

Then on animate both the height of your_container is adjusted and the margin-top on your_container and footer & .push are removed.

Hope this helps someone else when they stumble upon this.

J.

Jannis