The issue with your code is that you are using offset.top
, but you have no offset
variable declared, meaning that the .top
is not returning anything.
It seems that You've looked at the jQuery documentation for the offset(), but haven't understood/read the example properly.
At the documentation, they are initializing a variable:
var offset = $(this).offset();
And then extracting the .top
and .left
values:
alert(" coordinates: ( " + offset.left + ", " + offset.top + " ) ");
Looking at the web-page from your link, you don't need a very extensive script to check how much did the user scroll. This small function gives you what you need:
See this working Fiddle Example!
// getPageScroll() by quirksmode.com
function getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;
}
return new Array(xScroll,yScroll)
}
More reading about this can be found at this stackoverflow answer.