Dimensions
4 min read
Read dimensions with width(), innerWidth(), and outerWidth(). Get document-relative position with offset(). Read or set scroll position with scrollTop(). Essential for sticky headers, tooltips, and infinite scroll.
Getting Dimensions
$('#box').width(); // content width
$('#box').height();
$('#box').innerWidth(); // + padding
$('#box').outerWidth(); // + border
$('#box').outerWidth(true); // + margin
// Scroll position
$(window).scrollTop();
$(window).scrollLeft();
// Document height
$(document).height();