Link to home
Start Free TrialLog in
Avatar of SweatCoder
SweatCoderFlag for United States of America

asked on

scroll 2 frames together

Is there a way I can force two side-by-side vertical frames to scroll together as one? So that when you move the scrollbar on the left frame, the right frame scrolls with it, and vice versa?
Avatar of dynaweb
dynaweb

Yes, you can put those two frames (noscroll) inside one larger frame that allows scrolling.  That will make the two inside to scroll together :)
SOLUTION
Avatar of venkateshwarr
venkateshwarr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Something like this:

<script type="text/javascript">
<!--
var x=0;
var y;
function alignF()
{
if (top.frames['xxxxxx'].alignF
{
if (self.pageYOffset) // all except Explorer
{
      y = top.frames['xxxxxx'].pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
      // Explorer 6 Strict
{
      y = top.frames['xxxxxx'].document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
      y = top.frames['xxxxxx'].document.body.scrollTop;
}
}
setTimeout('alignF()',200);
}
onload=alignF;
//-->
</script>

Put it in the head of the pages and replace 'xxxxxxx' with the name of the other frame.

Cd&

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SweatCoder

ASKER

I tried both of your scripts, and neither of them worked. venkateshwarr, your script did nothing in my IE6 browser. cobol, your script was missing some parens and curly braces, so i fixed it up, and then tried various derivatives of your code. In 2 cases I got "not implemented" errors. In one case when I scrolled the left frame, it (left frame) went buggy and danced up and down, but the right frame never moved.

Sorry I didn't clarify--I am only interested in IE 5.5+ compatibility. My frame model is composed of 3 frames: PermsTop, PermsLeft, PermsRight.

When I scroll the left frame down, I need the right frame to scroll exactly with it, pixel-for-pixel. The 2 frames each have a table in which the row count always matches, so the vertical size of each frame is always identical, just FYI. I have to use 2 frames, can't combine into one, long story. Don't include any netscape stuff 'cause I won't need it.

Hope you can help. I've been on MSDN and tried some of the doScroll stuff, which also didn't work.
this ended up being the perfect solution:

var var_deltaY = 0;
  function doIt(){
      deltaY = document.body.scrollTop
      if(deltaY != var_deltaY){
            top.PermsRight.scrollTo(0,deltaY);
            var_deltaY = deltaY
      }
  }

<BODY onScroll="setInterval('doIt()',1)">

you both got me thinking in the right direction. . .i found the script above online and had to tweak it a bit, but it works great.
stop the presses, this is even better:

<BODY onScroll="top.PermsRight.scrollTo(0,document.body.scrollTop)">

that's it!!!! no extra javascript function required. that single line of code does EXACTLY what I needed, and elegantly too. this is an IE solution.