-1

Hey all I was just wondering how I would create an effect on jquery and/or javascript where when the user scrolled upwards, a div would appear.

Thanks!

aritro33
  • 227
  • 6
  • 13

1 Answers1

1

If you find a way to detect the scroll up event, then the whole process is too easy.

To detect scroll up I have used to below approach,

$(function () {
    //Keep track of last scroll
    var lastScroll = 0;
    $(window).scroll(function (event) {
        //Sets the current scroll position
        var st = $(this).scrollTop();
        //Determines up-or-down scrolling
        if (st > lastScroll) {
            //Replace this with your function call for downward-scrolling
            $('#up').hide();
        } else {
            //Replace this with your function call for upward-scrolling
            $('#up').show();
        }
        //Updates scroll position
        lastScroll = st;
    });
});

Keep a fixed positioned div and hide/show based on the scroll is what I have done.

JSFiddle

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Praveen
  • 55,303
  • 33
  • 133
  • 164