3

I'd like to have a div appear after a user scrolls down on a page, and disappears if they scroll back to the top.

I thought using the .scroll() function in jquery would be useful, but couldn't quite figure out how to make this happen.

Any help would be appreciated. Thanks!

IAdapter
  • 62,595
  • 73
  • 179
  • 242
Andelas
  • 2,022
  • 7
  • 36
  • 45

1 Answers1

14

Something like this should do the trick:

$(window).scroll(function() {
    if ($(this).scrollTop() == 0) {
        $("#mydiv:visible").hide();
    }
    else {
        $("#mydiv:hidden").show();
    }
});
chprpipr
  • 2,039
  • 16
  • 17