0

Let's say that I have a page which it's height is 1600px, and the viewport is 950px.

Is there anyway to get the unscrolled area's height?

For instance, when the page loads, the user didn't scroll at all, so the unscrolled area would be 1600-950 = 650.

If the user scrolled 100px , so the unscrolled area would be 1600-100-950 = 550

Thanks in advance!

kfirba
  • 5,231
  • 14
  • 41
  • 70

2 Answers2

1
function getUnscrolledArea(){
   return $(document).height() - $(window).height() - $(window).scrollTop();
}
omma2289
  • 54,161
  • 8
  • 64
  • 68
  • Well, this code returns a negative value for me. For some reason, my whole code is "bugged". whenever I use $(document).height or $(window).height I get the same result which is the WHOLE webpage heights. therefore, I can't center divs properly. So I thought that I can get the unscrolledarea and substract it from the $(document).height and then I will get the proper viewport which will make it possible to center divs. – kfirba Sep 16 '13 at 05:58
  • @kfirba what jQuery version are you using? can you provide a fiddle that reproduces your issue? – omma2289 Sep 16 '13 at 06:04
  • @koala_dev I'm using jQuery 1.10. I've tried to demonstrate the problem that I'm having using a fiddle, but I couldn't reproduce the error. This is my attempt to reproduce the error: http://jsfiddle.net/cK3XB/ – kfirba Sep 16 '13 at 06:21
1

Are you looking for:

var scroller = $('#overflowareaID');
var contents = scroller.wrapInner('<div>').children();
var viewportHeight = contents.outerHeight();
var unscrolledHeight=scroller.height()-viewportHeight;

Aown Raza
  • 2,023
  • 13
  • 29