Skip to content

Instantly share code, notes, and snippets.

@monkindey
Last active August 29, 2015 14:06
Show Gist options
  • Save monkindey/95f44ccc9e633f1c6b76 to your computer and use it in GitHub Desktop.
Save monkindey/95f44ccc9e633f1c6b76 to your computer and use it in GitHub Desktop.
offsetheight clientheight scrollheight区别
/**
* @author monkindey
* @date 2014-09-23
* @reference http://stackoverflow.com/questions/22675126/
* what-is-offsetheight-clientheight-scrollheight
*/
var $id = function(id){
return document.getElementById(id);
};
var box = $id('box');
var height = [{
name: 'clientHeight',
// visible height + padding = 303
value: box.clientHeight
}, {
name: 'offsetHeight',
// clientHeight + border + scrollbar
value: box.offsetHeight
}, {
name: 'scrollHeight',
// clientHeight + non-visible height
value: box.scrollHeight
}];
console.table(height);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment