Jace Cotton
Jace Cotton

Reputation: 2014

How to detect page overflow

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?

Upvotes: 1

Views: 816

Answers (2)

Mr_Green
Mr_Green

Reputation: 41832

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)

Upvotes: 1

Alex
Alex

Reputation: 4774

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.

Upvotes: 0

Related Questions