I know you can set the overflow property in CSS to determine what the page does on overflow, but I was wondering if there was any way to listen for page overflow using pure javascript or jQuery?
2 Answers
You can check by comparing offsetHeight and scrollHeight
var div = document.getElementById('main');
console.log(div.scrollHeight);
console.log(div.offsetHeight);
The element should have overflow: auto/scroll css property.
Working Fiddle (add content in the div to check)
Comments
You can do it with jQuery
$("element").css("overflow");
or
$("element").css("overflow-x");
I recommend you the 2nd example, because it should work in most browsers.
1 Comment
Jace Cotton
Wouldn't this just return the value of the
overflow property? I want to detect if the page has enough content to where it overflows.