|
Did you find an answer to this?
As far as I know it is not possible to determine.
|
|
Expert:
|
Anpanman
|
|
Date:
|
Aug 18, 2006
|
|
Time:
|
01:31
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
What I wonder is, how do you handle the width of your element? Why don't you set a width attribute lets say of 50 px and then check if the content of the box is greater than 50px. Then you know it has scrollbars.
Don't know if this helps you.
Cheers
Peter
|
|
Expert:
|
PeterNZ
|
|
Date:
|
Aug 27, 2006
|
|
Time:
|
22:13
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
Peter,
Your idea is actually what I have been using since I didn't get an answer to this question.
But actually I haven't checked if a browser will report the width or height to more that the actual width or height of the box even though it has overflowed (showing scrollbars).
What I do now is not to set "overflow: auto" and then just check if box.clientHeight has exceeded the maximun I choose. If it has, I remove the last item again. In IE this only works if the height of the box has been set in css. Otherwise it doesn't report the clientHeight property.
Peter, how would you suggest to "check if the content of the box is greater than 50px"?
Jakob
|
|
Expert:
|
jgivoni
|
|
Date:
|
Aug 28, 2006
|
|
Time:
|
14:06
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
I finally found a way to check if an element has a scrollbar.
It is actually quite simple, since if there is a scrollbar it will take up some space inside the element.
If the elem.style.width is greater than elem.clientWidth (about 14-16 px difference), then it suggest that the element has a vertical scrollbar.
|
|
Expert:
|
jgivoni
|
|
Date:
|
Nov 20, 2006
|
|
Time:
|
15:46
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
This can be used for various purposes, - for instance to automatically expand a textarea box when it get's full:
<textarea style="width: 200px height: 50px; overflow: auto" onkeyup="textarea_size(this)"></textarea>
<script>
function textarea_size(elem)
{
w1 = elem.style.width.replace(/[^\d]/g, "");
w2 = elem.clientWidth;
if ((w1 - w2) > 10)
{
h = elem.style.height.replace(/[^\d]/g, "");
elem.style.height = parseInt(parseInt(h) + 8) + "px";
textarea_size(elem);
}
}
</script>
This example is quickly written and briefly tested on FF2.0 and IE 6. There is most probably room for improvement.
For instance, it is assumed that the width and height is set in pixels and that the scrollbar has not been modified to be narrower that 10px...
|
|
Expert:
|
jgivoni
|
|
Date:
|
Nov 20, 2006
|
|
Time:
|
16:09
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
Since my last answer (to my own question) I've found a much better solution.
I've discovered the element property "scrollHeight"!
Read more about it in the summary.
|
|
Expert:
|
jgivoni
|
|
Date:
|
Feb 11, 2007
|
|
Time:
|
13:49
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
|
|
|
|
This question has been answered, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.
|
|