Man what a pain in the ass this is. I'm still working out some additional details that were pointed out to me with the wwHoverPanel control. The main problem is that reliably getting the scroll position is very fickle.
Originally I had tried to rely on document.body.scrollTop which works fine for the original demos I created, but it fails when running in a MasterPage. I don't think it's the master page per se that is making this different, but probably the containership inside of the body tag.
In any case in the more complex page document.body.scrollTop returns false and this is were things diverge in browsers with IE requiring the use of the parentElement (HTML) and FireFox using pageYOffset which is a non-standard tag (so much for FireFox always following standards).
The code that actually seems to work in the scenarios I tried is this:
var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0)
{
if (window.pageYOffset)
ScrollTop = window.pageYOffset;
else
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
So let's see here, we have scrollTop on different containers and we have pageYOffset neither of which seems particularily clear description of the task. The window should have a scroll position because that's really what we're after in this case…
I hate browser scripting… <g>
(and yes I know what you're going to say Bertrand – "that's why we're doing it for you…" <g>).
Thanks for Chris and Mike McDonald for all their comments on some of this stuff. If you want to follow this discussion related to wwHoverPanel movement closer you can click here and here.
Other Posts you might also like