Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect elements overflow using jquery

Tags:

jquery

CSS:

 .blue     {      width:200px;      height:200px;      background-color:blue;      color:#000000;      overflow:auto;     } 

JavaScript:

function addChar() {     $('.blue').append('some text  '); } 

HTML:

<div id='blue1' class="blue"></div><br /> <a href='javascript:void(0)' onclick='addChar()'>Add</a> 

div id='blue1' has overflow property set to auto. I want to detect overflow when it happens.

like image 741
Praveen Prasad Avatar asked Jan 13 '10 19:01

Praveen Prasad


People also ask

What is offsetHeight in jQuery?

Definition of jQuery offsetHeight. In jQuery, we can get the height of an element by using the offsetheight property in it. It is an in-built property of jQuery we can use it directly to get the viewable height of an element.

What is element overflow?

In CSS, overflow refers to any content that is too big for an element's box. This occurs when a block element has a specified height that's too small for the content it contains. You can use the CSS overflow property to control what happens to the overflow.


1 Answers

$.fn.HasScrollBar = function() {     //note: clientHeight= height of holder     //scrollHeight= we have content till this height     var _elm = $(this)[0];     var _hasScrollBar = false;      if ((_elm.clientHeight < _elm.scrollHeight) || (_elm.clientWidth < _elm.scrollWidth)) {         _hasScrollBar = true;     }     return _hasScrollBar; } 

/// this is my solution

like image 122
Praveen Prasad Avatar answered Oct 17 '22 02:10

Praveen Prasad