What happens if you compare (window).height() with (document).height() , if the height of the document is greater than the height of the window, then the scroll bar should be visible, but it also depends on your CSS settings and on hidden or visible overflow.
EDIT
You need to create a listener so that the code works at the right time. This should work when resizing the browser window:
$(window).resize(function(){ var hContent = $("body").height(); var hWindow = $(window).height(); if(hContent>hWindow) { $('#scroll-top').fadeIn(250); } else { $('#scroll-top').fadeOut(250); } }
source share