2

I have the following HTML

<header class="fixed">...</header>
<div id="content">
    <div id="sidemenu" class="fixed">...</div>
    <div id="scroll">...</div>
</div>
<footer class="fixed">...</footer>

With various positioning rules in the CSS and the rule

.fixed {
    position: fixed;
}

This achieves the desired affect of only the div with id scroll moves. However, this can leaves the footer out of view.

What I want to do, is once the bottom of the scroll div reaches the bottom of the footer, change position: fixed to position: absolute and then everything will scroll up together revealing the footer.

But I don't know how to do it. I was looking at waypoints but I'm in a little over my head.

2 Answers 2

1

something like this should solve the problem of yours. try this:

$(window).scroll(function () {
    var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();

    if (scrollBottom <= $("footer").height()) {
        $("footer").css("position", "absolute");
        } 
        else {
            $("footer").css("position", "fixed");
        }
});
Sign up to request clarification or add additional context in comments.

Comments

0

For that, you will have 'onScroll' event. And check when the coordinates of the scroll div matches that of the footer. As soon as they match, change the position to 'absolute' in the implementation of handler.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.