George Halls
George Halls

Reputation: 11

$(window).scrollTop() returnig 0

Currently trying to get something to trigger when a div is close to the top of the window with the following code within document.ready however wScroll is always returning 0 I have checked that html, body tags do not how height:100% have attached to them which they don't any ideas where I am going wrong?

var wScroll = $(window).scrollTop();
console.log(wScroll);
if($('#about-me').offset().top < wScroll) {
    alert("wi");
    $('#about-me').html("Working");
    console.log("working");
}

Upvotes: 0

Views: 80

Answers (1)

Ryan Dantzler
Ryan Dantzler

Reputation: 1144

You need to wrap your code in the an onScroll event handler

$(window).on('scroll', function() {...});

Upvotes: 1

Related Questions