-4

I made an illustration of what I am trying to do: https://i.stack.imgur.com/GLEuM.png

This is what I am looking to do:

  • Stick '#Stick to Top' to top of page after scrolling past '#Header'.
  • Hide '#Stick to Top' until scrolled past '#Header'. Hide again when scrolled back up to '#Header'.

How can I achieve this?

John
  • 39
  • 1
  • 5
  • You can use jquery-visible plugin to test whether a header is partially visible or not and then adjust the styles appropriately: http://jsfiddle.net/xyy4pdca/. – DRD Oct 29 '14 at 22:14

1 Answers1

0

I had a similar issue where I wanted the header to stay locked to the top of the screen. Try the following (untested) code.

    if($(window).scrollTop() > Height_of_Header){
        //begin to scroll
        $("#div").show();
        $("#div").css("position","fixed");
        $("#div").css("top",0);
    }
    else{
        //hide
        $("#div").hide();
    }
lmno
  • 1,004
  • 1
  • 15
  • 27