Solved

.scrollTop read ONLY in netscape?

Posted on 2003-11-07
6
736 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:newbee2MFC
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Zontar
ID: 9706534
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.)
0
 

Author Comment

by:newbee2MFC
ID: 9707798
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>
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9708585
#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);"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:newbee2MFC
ID: 9708838
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
0
 
LVL 15

Expert Comment

by:JakobA
ID: 9709070
???  YARNTUMSIETOLDS* ???
0
 
LVL 11

Accepted Solution

by:
Zontar earned 40 total points
ID: 9709271
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"];
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now