0

I really cannot figure it out how can I accomplish this. I need to have a footer partially visible all the time at the bottom. When you hover it shows up entire height of 400px, then get back to the original position. The problem that I have is with the scroll function. I do not know how to set it properly. The result I am looking for is when you scroll all the way down (without hovering) the footer needs to take the full height, if you scroll up the footer goes back to the original position.

Here is the jsFiddle (I hope it works, this is the first time when I use this).

Below is the code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">

    $(window).scroll(function () {

        if ($(window).scrollTop() > $('#move').position() -500) {
            $('#footer').css('bottom', 0);
        }
        else {
            $('#footer').css('bottom', -300);
        }
    });

    $(document).ready(function () {

        $('#footer').bind('mouseenter', function () {

            $(this).stop().animate({ bottom: 0 }, 400); // on hover  0 400  

        }).bind('mouseleave', function () {

            $(this).stop().animate({ bottom: -300 }, 400); // on out -300  400

        });
    });

             </script>
<style>
    html, body{

    }
    #footer {
        position: fixed;
        z-index: 999;
        bottom: -300px;
        width: 100%;
        height: 400px;
        background-color: #999;
        opacity:0.5;

    }
    #content {
        padding-bottom: 100px;

    }

    #move {
        height:auto;
        top: 5000px;
        position: relative;
        background-color:red;
    }
</style>

</head>

<body>

<div id="content">

<h1 id="move"> end content </h1>

</div>

<div id="footer">

this is the footer

</div>

</body>
</html>
mdml
  • 22,442
  • 8
  • 58
  • 66
valentin
  • 5
  • 3

1 Answers1

0

Updated fiddle: http://jsfiddle.net/moonspace/ZCger/1/

Add this JS into your '$(window).scroll(function () {}'

if( $(window).scrollTop() + $(window).height() == $(document).height() ) {
        $('#footer').css('bottom', 0);
    }
Pat Dobson
  • 3,249
  • 2
  • 19
  • 32
  • Thank so much Pat. I am trying to understandd the scrollTop actualy is the 0px on y. But $(window).height() == $(document).height() I do not know. Do you mind if you explain to me the logic? Document = the ID content? – valentin Dec 03 '13 at 16:02
  • scrollTop is basically the height of the page above the top of the browser, height is the height of the displayed page so, added together they create a number which, when equal to the entire document height says 'the user is at the page bottom'. - does that make sense ? – Pat Dobson Dec 03 '13 at 16:05
  • Great, I really appreciate your help. If I like to have the same smooth movement as a hover does, I just to add the animate function . Am I right?My best regards – valentin Dec 03 '13 at 16:16
  • Yes, animate() instead of css() (with the correct syntax) will provide (for example) a sliding effect. – Pat Dobson Dec 03 '13 at 16:28
  • Mark my answer as 'accepted' and you might just make my day :) – Pat Dobson Dec 03 '13 at 20:07
  • Pat, there is a way to work the above solution on mobile devices such as Android or iPhone? I've tried on my cell and just the hover is working which on mobile version does not make more sense. The scrollTop function not working. Any idea? Thanks in advance. – valentin Dec 03 '13 at 20:59
  • Scrolling as an event is problematic on mobile. In a desktop browser it 'fires' constantly so updating is nice and smooth. On mobile (phone, tablet) it only fires at the end & end of the scroll. Have a look here : http://stackoverflow.com/questions/7879417/how-to-capture-scroll-start-event-on-iphone-android – Pat Dobson Dec 03 '13 at 21:41