Javascript if scroll position > 100

Alpan Karaca picture Alpan Karaca · Jul 24, 2013 · Viewed 16.2k times · Source

How can I test it if it's greater than 100. For example how can I get an alert.

Here is my code that doesn't work, I don't know why.

var ScrollTop = $("body").scrollTop();

if (ScrollTop > 100){
    alert("Scroll is greater than 100");
    //document.getElementById('back-to-top').fadeOut;
}

Answer

verbanicm picture verbanicm · Jul 24, 2013

Use a scroll listener http://jsfiddle.net/6A6qy/

$(window).scroll(function(){...});