views:

28311

answers:

4

I need to grab the height of the window and the scrolling offset in jQuery, but I haven't had any luck finding this in the jQuery docs or Google. I'm 90% certain there's a way to access height and scrollTop for an element (presumably including the window), but I just can't find the specific reference.

Any help is appreciated! Thanks!

+3  A: 

$(window).height()

$(window).width()

there is also a plugin to jquery to determine element location and offsets

http://plugins.jquery.com/project/dimensions

scrolling offset = offsetHeight property of an element

Joey V.
Thanks, Joseph. It's not exactly what I was looking for as I was trying to avoid using another plugin, but you got me searching in the right direction. In the end, it turns out what I really needed was '$(window).scrollTop()' to figure out how much of the page has scrolled past the viewport to adjust elements accordingly.
DA
oops. wrong thread. Still, my comment applies. ;)
DA
+41  A: 

From jQuery Docs:

var height = $(window).height();
var scrollTop = $(window).scrollTop();

http://docs.jquery.com/CSS/scrollTop
http://docs.jquery.com/CSS/height

Pim Jager
Figures I just missed it in the docs; searched them, but their organization frankly makes no sense to me (still thinking in Mootools, I suppose). Thanks!
One Crayon
This doesn't work in any browser for jQuery 1.3.2 even though it was supposedly added in an earlier version. Either that or I have something wrong with my code here
Philluminati
You probably do. :)
Paul Shapiro
A: 

$("body").height()

Micah Burnett
A: 

from http://api.jquery.com/height/

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document

from http://api.jquery.com/scrollTop/

$(window).scrollTop() // return the number of pixels scrolled vertically
Aidamina