Reputation: 463
i want that when a div increase than a height i have set, then only it should show scroll bar, otherwise the inactive scrollbar should also not be shown.
i am using the following code for this:
$(document).ready(function(){
if($('.dialog-text').height()<=119 ){
$(this).css('overflow-y', "hidden");
}
else{
$(this).css('overflow-y', "scroll");
}
});
obviously i must have done something wrong. please point it out or give a better solution.
Upvotes: 0
Views: 267
Reputation: 16777
Just use the auto
value of overflow-y
.
Remove the JS you've added, and add this style to the CSS:
.dialog-text
{
height: 119px;
overflow-y: auto;
}
auto value for overflow
Depends on the user agent. Desktop browsers like Firefox provide scrollbars if content overflows.
Upvotes: 3
Reputation: 4160
Your code only runs once, when your site loads. If your div changes content after loading then you need make a function to check the height and modify it if needed immediately after changing the content of the div, or use something like attrchange to listen to the height changes of the div, and hide the scrollbar if necessary.
Upvotes: 0