Re: Calculating the actual content width or height



David Mark wrote:
On Dec 15, 9:18 am, r_honey <singlarahu...@xxxxxxxxx> wrote:
I am trying to scroll text across a <div>. For doing this, I need to
know the actual width the content of the div consumes (not the width
or offset width of the div, but the actual width of the contents,
irrespective of whether the div itself is larger or smaller than the
actual content width).

Is there any way of knowing this in java script??

div.scrollWidth

No, unfortunately that includes padding area, so it doesn't answer the OP question.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html lang="en">
<head>
<title>scrollWidth</title>
<script type="text/javascript">
onload = function() {
var d = document.getElementById('d'),
f = document.getElementById('f'),
textContent = "textContent";
if (! (textContent in document.body))
textContent = "innerText";
f[textContent] = d.scrollWidth;

};
</script>
</head>
<body>
<h1>scrollWidth</h1>
<div id="d" style="width: 10px; padding: 100px; background: lime">width: 10px; padding: 100.5px</div>
scrollWidth: <b id="f"></b>
</body>
</html>

FF 3
scrollWidth: 211

Safari 2, Safari 3, Opera 9.5:
scrollWidth: 210

The OP was very specific in that he wants to obtain the content area. I would also like a simple solution to this problem.

Garrett

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
.



Relevant Pages