.scrollTop read ONLY in netscape?

Here is the sample code:

oElement = document.getElementById("div1");
oElement.scrollTop = 20;

looks like scrollTop is ready only in Netscape?  same code works fine in IE.  I could not change the value

any ideas?

Thanks
g
newbee2MFCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZontarCommented:
YARNTUMSIETOLDS*

You need to sue

oElement.style.top = "20px";

This is the W3C standard and is cross-browser compatible syntax.

elemetObject.style.propertyName = value;

value is always a string -- sizes, distances, etc. must have units.

CSS properties that are hyphenated adopt intercap notaiton in script, e.g.
CSS -->>  CSS DOM
border-style:solid -->> elementObject.style.borderStyle = "solid";
margin-top:.3em -->> elementObject.style.marginTop = ".3em";
list-style-type:disc; -->> elementObject.style.listStyleType = "disc";
etc.

(*Yet Another Reason Not To Use MSIE to Learn DOM Scripting.)
newbee2MFCAuthor Commented:
What I really want to do is to get rid of the scroll bars for div2 and div1,  I am wondering if there is work around on this

Please see the enclosed script. Thanks
=============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <style>#div1 {
      OVERFLOW: auto; HEIGHT: 184px
}
#div2 {
      OVERFLOW: auto; WIDTH: 284px
}
#div3 {
      OVERFLOW: auto; WIDTH: 300px; HEIGHT: 200px
}
BODY {
      FONT-SIZE: 8pt; FONT-FAMILY: Tahoma
}
  </style>
  <script language="JavaScript">

function getOnScrollFunction(event)
{
      oElement = document.getElementById("div2");
      if ( event.srcElement )
            oElement.scrollLeft = event.srcElement.scrollLeft;
      else
      {
            oElement.scrollLeft = event.target.scrollLeft;
      }

      oElement = document.getElementById("div1");
      if ( event.srcElement )
            oElement.scrollTop = event.srcElement.scrollTop;
      else
      {
            oElement.scrollTop = event.target.scrollTop;
      }
}

  </script>
  <meta content="MSHTML 6.00.2800.1264" name="GENERATOR">
</head>
<body style="background-color: rgb(255, 255, 255);">
<table cellspacing="0" cellpadding="0" border="0">
  <tbody>
    <tr>
      <td valign="top">
      <div id="div0">
      <table cellspacing="1" cellpadding="8" bgcolor="#000000"
 border="0">
        <tbody>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="60">Col 1</td>
          </tr>
        </tbody>
      </table>
      </div>
      <div id="div1">
      <table cellspacing="1" cellpadding="8" bgcolor="#000000"
 border="0">
        <tbody>
          <tr bgcolor="#f5deb3">
            <td nowrap="nowrap" width="110" height="70">Row 1</td>
          </tr>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="70">Row 2</td>
          </tr>
          <tr bgcolor="#f5deb3">
            <td nowrap="nowrap" width="110" height="70">Row 3</td>
          </tr>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="70">Row 4</td>
          </tr>
        </tbody>
      </table>
      </div>
      </td>
      <td valign="top">
      <div id="div2">
      <table cellspacing="1" cellpadding="8" bgcolor="#000000"
 border="0">
        <tbody>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="60">Col 1</td>
            <td nowrap="nowrap" width="110" height="60">Col 2</td>
            <td nowrap="nowrap" width="110" height="60">Col 3</td>
            <td nowrap="nowrap" width="110" height="60">Col 4</td>
          </tr>
        </tbody>
      </table>
      </div>
      <div id="div3" onscroll="getOnScrollFunction(event);">
      <table cellspacing="1" cellpadding="8" bgcolor="#000000"
 border="0">
        <tbody>
          <tr bgcolor="#f5deb3">
            <td nowrap="nowrap" width="110" height="70">Row 1 Col 1</td>
            <td nowrap="nowrap" width="110" height="70">Row 1 Col 2</td>
            <td nowrap="nowrap" width="110" height="70">Row 1 Col 3</td>
            <td nowrap="nowrap" width="110" height="70">Row 1 Col 4</td>
          </tr>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="70">Row 2 Col 1</td>
            <td nowrap="nowrap" width="110" height="70">Row 2 Col 2</td>
            <td nowrap="nowrap" width="110" height="70">Row 2 Col 3</td>
            <td nowrap="nowrap" width="110" height="70">Row 2 Col 4</td>
          </tr>
          <tr bgcolor="#f5deb3">
            <td nowrap="nowrap" width="110" height="70">Row 3 Col 1</td>
            <td nowrap="nowrap" width="110" height="70">Row 3 Col 2</td>
            <td nowrap="nowrap" width="110" height="70">Row 3 Col 3</td>
            <td nowrap="nowrap" width="110" height="70">Row 3 Col 4</td>
          </tr>
          <tr bgcolor="#ffffff">
            <td nowrap="nowrap" width="110" height="70">Row 4 Col 1</td>
            <td nowrap="nowrap" width="110" height="70">Row 4 Col 2</td>
            <td nowrap="nowrap" width="110" height="70">Row 4 Col 3</td>
            <td nowrap="nowrap" width="110" height="70">Row 4 Col 4</td>
          </tr>
        </tbody>
      </table>
      </div>
      </td>
    </tr>
  </tbody>
</table>
</body>
</html>
ZontarCommented:
#div1 {
     OVERFLOW: hidden; HEIGHT: 184px;
}
#div2 {
     OVERFLOW: hidden; WIDTH: 284px;
}

Gets rid of the scrollbars.

To understand why the synchronised scrolling won't work as you've written it in NS 6+/Mozilla once you change the overflow property to "hidden", you need to look at what the W3C spec says about the overflow property ( http://www.w3.org/TR/CSS2/visufx.html#x0 ):

hidden
    This value indicates that the content is clipped and that no scrolling mechanism should be provided to view the content outside the clipping region; users will not have access to clipped content. The size and shape of the clipping region is specified by the 'clip' property.
scroll
    This value indicates that the content is clipped and that if the user agent uses scrolling mechanism that is visible on the screen (such as a scroll bar or a panner), that mechanism should be displayed for a box whether or not any of its content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment.

In other words, according to the spec, you either allow scrolling, which means scrollbars, or you don't allow scrolling, which means no scrollbars, and vice versa: n scrollbars: scrolling; no scrollbars: no scrolling. But, as it so often does, MSIE breaks the spec.

If you want to emulate MSIE's nonstandard behaviour, you've two choices:

1. Get rid of the divs and use iframes.

2. For compliant browsers, use dynamic positioning and clipping, e.g. elementObject.style.clip = "rect(5px, 10px, 10px, 5px);"
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

newbee2MFCAuthor Commented:
I do not understand,  iframe or clip would good for this as it mean to be used for server side call back.  What I what is to control the view port of the data object already in browser cache

can you give a simple example?

Thanks
George
JakobACommented:
???  YARNTUMSIETOLDS* ???
ZontarCommented:
JakobA,

If you'd read my whole post, you'd have seen the definition. ;-)

newbee,

If you need to to submit data back to the server, then iframe is probably not the best solution. That means clipping. Here's a basic example of what I'm talking about, with a div (Mozilla / NS6+ / Gecko-based browsers only):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Basic Scrolling Example Using Dynamic Clipping</title>

<style type="text/css">

#myDiv  { position:absolute; left:100px; top:100px;
          visibility:visible; overflow:hidden;
          width:auto; height:75px;
          clip:rect(0px 100px 75px 0px);
          background-color:#FFE;  }

</style>

<script type="text/javascript">

function scrollIt()
{
  var myDiv = document.getElementById("myDiv");
  var currLeft = myDiv.offsetLeft;
  var newLeft = currLeft - 5 + "px";

  var currClip = document.defaultView.getComputedStyle(myDiv, "").getPropertyValue("clip");
  clipValues = currClip.slice(5, -3).replace(/px,/g, "").split(" ");
  clipTop = clipValues[0] - 0;
  clipRight = clipValues[1] - 0;
  clipBottom = clipValues[2] - 0;
  clipLeft = clipValues[3] - 0;
  newClip = "rect(" + clipTop + "px, " + (clipRight + 5) + "px, " + clipBottom + "px, " + (clipLeft + 5) + "px)"

  myDiv.style.left = newLeft;
  myDiv.style.clip = newClip;
}

function startScroll()
{
  window.timer = setInterval("scrollIt()", 200);
}

function stopScroll()
{
  clearInterval(window.timer);
}

</script>

</head>
<body>

<div id="myDiv">
  <table width="450" height="75" cellpadding="5" cellspacing="0" border="1">
    <tr>
      <td width="75"> ... CELL 1 ... </td>
      <td width="75"> ... CELL 2 ... </td>
      <td width="75"> ... CELL 3 ... </td>
      <td width="75"> ... CELL 4 ... </td>
      <td width="75"> ... CELL 5 ... </td>
    </tr>
  </table>
</div>

<form>
  <input type="button" value="scroll..." onmousedown="startScroll();" onmouseup="stopScroll();">
</form>

</body>
</html>

Summary: each time the scrollIt() function is executed, the div is moved 5px to the left and its clipping rectanlge is moved 5px to the right.

Explanation of clipping, with a couple of helpful diagrams:

 http://www.w3.org/TR/CSS2/visufx.html#propdef-clip

This can also be done in MSIE, although the mechanism for obtaining the current value of a style property is a little different:

var currClip = el.currentStyle["clip"];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.