I am trying to write code to a div telling a user how far he has scrolled down the page. Here is my code:
$(document).scroll(function(){
var fullHeight = $(this).height();
var currentHeight = $(this).scrollTop();
var percentageOfPage = currentHeight/fullHeight;
percentageOfPage = percentageOfPage.toFixed(2);
var t = $("#t");
t.html("You are " + percentageOfPage + " down this page." );
});
fiddle
The code works mostly how it should: it writes out the percentage how far a user has scrolled. But it stops at about .67 or .69. Why does it do that? I want it to go all the way to 1. Also, how can I display it as a percentage, like 60%, instead of a decimal, like .6? here is where the page is.
ADDITION:
How can I make it so that at the when the user reaches the bottom of the page, the message becomes: "You have reached the bottom of the page", instead of the percentage?