473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Sync scrolling of divs (not frames)

I'm trying to synchronize the scrolling of two <div> elements. The
top element is for showing column headers, the bottom div shows the
table rows.

I consed up the following HTML/JavaScript concoction which does
something useful in IE and also in Mozilla 1.4.

However, the problem is that it only works in Mozilla if I say
overflow:auto in the top frame, it ceases working if I say
overflow:hidden. But saying overflow:hidden is desirable because it
eliminates a superfluous scrollbar. overflow:hidden works in IE.

Any suggestions on getting rid of the scrollbars in Mozilla, too?

tia,
Kai

<html>
<head>
<title>Testing div scrolling</title>
<script language="JavaScript">
<!-- // Begins
var topdiv;
var bottomdiv;
IE = (document.all) ? true : false;
last_x = 0;
last_y = 0;
function synchronizeScroll() {
if (bottomdiv.scrollLeft) {
topdiv.scrollLeft = bottomdiv.scrollLeft;
}
}
// Ends -->
</script>

</head>
<body onScroll="synchronizeScroll()"
onLoad="if (!IE) window.setInterval('synchronizeScroll()',
100);">

<div id="topdiv" style="width:200px;overflow:auto">
<pre>123456789|123456789|123456789|123456789|12345 6789|123456789|123456789|</pre></div>
<hr>
<div onScroll="synchronizeScroll()"
id="bottomdiv" style="width:200px;height:100px;overflow:scroll">
<pre>
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yzabcdefghijklmnopqrstuvwxyz
</pre>
</div>
<script language="JavaScript">
topdiv = document.getElementById('topdiv');
bottomdiv = document.getElementById('bottomdiv');
</script>
</body>
</html>
Jul 20 '05 #1
5 14559
Ka*************@gmx.net (Kai Grossjohann) wrote in message news:<e8**************************@posting.google. com>...

However, the problem is that it only works in Mozilla if I say
overflow:auto in the top frame, it ceases working if I say
overflow:hidden. But saying overflow:hidden is desirable because it
eliminates a superfluous scrollbar. overflow:hidden works in IE.

Any suggestions on getting rid of the scrollbars in Mozilla, too?


It turns out that overflow:-moz-scrollbars-none works in Mozilla: the
scrollbars are hidden, yet I can scroll programmatically.

So now I have this horrible piece of JavaScript which frobs the DOM to
change the overflow attribute if running in Mozilla. Suggestions for
improvements are most appreciated.

if (topdiv.style.MozAppearance == "") {
// We seem to be running in Mozilla, so let's frob the overflow
attribute.
topdiv.style.overflow = '-moz-scrollbars-none';
}

I'm not sure about the test that finds out if we are running Mozilla.

Cheers,
Kai
Jul 20 '05 #2
Kai Grossjohann wrote:
It turns out that overflow:-moz-scrollbars-none works in Mozilla: the
scrollbars are hidden, yet I can scroll programmatically.

So now I have this horrible piece of JavaScript which frobs the DOM to
change the overflow attribute if running in Mozilla. Suggestions for
improvements are most appreciated.

if (topdiv.style.MozAppearance == "") {
// We seem to be running in Mozilla, so let's frob the overflow
attribute.
topdiv.style.overflow = '-moz-scrollbars-none';
}

I'm not sure about the test that finds out if we are running Mozilla.


You are testing the wrong thing. Test if the property is available, then
you can hope for the rest of the `style' property to work as supposed:

if (typeof topdiv.style != "undefined"
&& typeof topdiv.style.MozAppearance != "undefined")
{
...
}

The same goes for your `IE' boolean variable. See
http://pointedears.de.vu/scripts/test/whatami for details.

And please use http://validator.w3.org/, your HTML is far from valid.

Have you ever thought of users without client-side JavaScript support?
PointedEars
Jul 20 '05 #3
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Have you ever thought of users without client-side JavaScript support?


I try not to think of them poor buggers. Makes me feel sad.

Some day, the result will enter the annals of history as the web app
that violates all web and accessibility guidelines in existence.

Please excuse me while I find a rock to hide under,
Kai
Jul 20 '05 #4
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
You are testing the wrong thing. Test if the property is available, then
you can hope for the rest of the `style' property to work as supposed:

if (typeof topdiv.style != "undefined"
&& typeof topdiv.style.MozAppearance != "undefined")
{
...
}
Ah, right. I see that I was thinking in the right direction. I will
learn. I've only been doing this JavaScript stuff for two weeks,
before that time I didn't even know how to spell JavaScript...

Thanks for teaching me.
The same goes for your `IE' boolean variable. See
http://pointedears.de.vu/scripts/test/whatami for details.
Thanks. I copied the IE variable from a tutorial or sample snippet
somewhere. It was good enough for a quick exploration, but I'll
replace it, as I learn more.
And please use http://validator.w3.org/, your HTML is far from valid.


OK. I guess there is also a command-line version, I've been wanting
to have this for quite a while now. Maybe even somebody has something
for Eclipse...

Kai

Jul 20 '05 #5
Kai Grossjohann wrote:
Thomas 'PointedEars' Lahn [...] writes:
And please use http://validator.w3.org/, your HTML is far from valid.
OK. I guess there is also a command-line version, I've been wanting
to have this for quite a while now.


http://validator.w3.org/source/
http://www.w3.org/People/Raggett/tidy/
Maybe even somebody has something for Eclipse...


http://sourceforge.net/project/showf...ease_id=194394
HTH

PointedEars
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hugh Dickinson | last post by:
Does anybody know whether the netscape 7+ browsers support afunction similar to the internet explorer doScroll() function, this has the effect of pressing the scrollbar button, but can be scripted...
0
by: nina | last post by:
Hi all, I've been working on a site that involves content in multiple scrolling DIVs on a page which is loaded inside multiple framesets. the layout is cramped as all hell but I'm not going to...
5
by: Frances Del Rio | last post by:
why do I keep getting scroll bars on frames even though I have scrolling set to "no"?? (am on IE..) I mean even if you put an img in there or sthg that's a bit larger than the frame if you set...
3
by: Gianni Rondinini | last post by:
i'm talking about this page: http://www.elleen.net/yanny/prova.html colours are awful, but they're there just to realize where divs begin and end. in firefox it works pretty good --well, at least...
13
by: al jones | last post by:
I guess one question at a time will work better. URL http://aljones.us (yes, I'm back again) I'd like to cause this whole page to fill the viewable window if I can. Meaning that I'd like the...
0
by: nan | last post by:
Please give me some tips or some source code by using which able to make the avi file for audio and video data to play in sync. Some details are given below: I noticed that many times the video...
8
by: knoxautoguy | last post by:
This problem has consumed a lot of my time, and I'm aftraid someone will tell me that my whole approach to this objective is wrong; however, I would like to know if there is a way to do this. I...
5
by: Gary | last post by:
If one has two iframes side by side is it possible to get them both to scroll when the user scrolls one of them? If it is possible is there a reference that will help me in solving this. ...
0
by: stan | last post by:
I have internal links/jumps within divs. The divs have vertical scrolling. When a link is clicked, both the space within the div as well as the entire page vertically scroll. I would like to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.