Hello Javascript experts! I am in sore need of your help!
I have two DIVS, one for a table body, and one for the column headers. The table has lots of columns, so horizontal scrolling is a must. I am trying to make it so that when the body div is scrolled left or right, the header div scrolls along with it. Unfortunately one of the requirements of the project is that it must work on MAC/IE5.2.2, and the “scrollLeft” property on this browser only works for the “document.body” element. Because of this I cannot for the life of me figure out how to get the distance that the table body div has scrolled.
I have also tried using overflow-x and overflow-y to work around this, but it seems these properties aren’t supported by MAC/IE5.2.2 either.
So is there a way to synchronize the scrolling of two divs, or perhaps a completely different way to accomplish what I am trying to do? Any help will be greatly appriciated!
Ya - just absolutely position one inside the other, or both absolutely positioned inside a 3rd, innocuous DIV. Then you only have to manage scrolling for one, and the CSS will take care of the rest.
I would do that, except I want the table body div to be able to scroll vertically while the header div remains on the screen. I guess I should have mentioned that in my post.
No, its a long and wide table that scrolls both vertically and horizontally. But the headings should always stay on top, so they must be affected by the horizontal scrolling, but not the vertical scrolling.
It must also work on Win/IE6.0, and it does that right now.
According to the MSDN Reference for scrollLeft, IE Mac supports this property for both DIV and TABLE elements from version 4 on up, which obviously includes 5.2. Is this not accurate?
Nope, its not accurate at all. scrollLeft works for document.body on IE Mac, but for elements inside of body it always returns 0. MSDN does not seem to be all that accurate when it comes to listing features supported for IE Mac. For example, the swapNode() method is supposed to be supported, but its not.
Look into the API at www.cross-browser.com. Mike Foster, the author, is a member here and uses this forum for his support. I don’t have much for-Mac DHTML experience, and if MSDN doesn’t help, then a well written API like the x or cbe libraries is gonna be your best bet.
Well, it seems the cbe’s scrollLeft() method makes use of the IE scrollLeft property, so the same problem remains.
In any case, it seems to me that any API like cross-browser still depends on methods and properties supported by the specific browser viewing the page. That is, you can create all the new classes you want, but if the browser has no way of telling your classes how much an element has been scrolled, there’s nothing you can do about it without going into the guts of the browser itself.
Hi Kalirion. I played around with a few variations of beetle’s original suggestion, but without scrollLeft I can’t see how to do it using overflow:auto.
As far as using a dhtml API, I think beetle is referring to using a dhtml scroller (not using the built-in scrolling capability of IE elements). This would not rely on the scrollXxx properties. It would implement scrolling from scratch. (It will also have to implement scrollbars and dragging.)
I don’t have any examples that fit your particular need. I started on one, but I may not have much time this week to put into it.
There are other authors who already have dhtml scrollers implemented. Are you interested in this dhtml solution?
What’s frustrating is that this ‘built-in scrolling support’ seems to be outside the object model. If you were to implement scrolling using clipping - then you would have to clip and move. Clipping sets the viewport size. Moving keeps the viewport in the same position (for the user) and simulates scrolling. However, neither the clip nor position properties change when scrolling with the built-in scroll support. I found this to be true in Firebird as well.
Here’s what I was trying, but it uses ele.scrollTop - so this may not work in IE5/Mac.
Thanks Mike! Unfortunately scrollTop works no better on IE Mac than scrollLeft does. The DHTML scrollers might work, but it seems like too much effort for one little feature. Right now I’ve used the backslash comment hack to put the scroll bars on the DIV containing both the table headers and the data. This means that on the Mac, the headers won’t be visible if the table is scrolled vertically, by my boss and I decided that wasn’t such a big loss. Especially since for unrelated performance reasons, the table won’t be allowed to be longer than maybe 50 entries at a time.
Thanks again to everyone who tried to help! When I have other questions regarding Javascript and DHTML, I’ll be sure to bring them to this form :). Now lets all hope the MAC IE division gets their act straight sometime in the near future.
Found this thread via the link above. I had a similar problem some time ago and was able to solve it after a lot of trial and error. The only caveat is that I haven’t set any doctype since the code is a bit hackish. Check it out here: