I have 2 divs in fixed positions on my page, the idea is that their contents scroll when the page scrolls. However, when using Firefox, when there are many other DOM objects on the page, the movement (especially vertical) is very jerky. Performance is thin in chrome and IE7 / 8. The code is shown below -
If anyone can indicate how this can be optimized or simplified, I would be very grateful!
I bind my window scroll event like this:
$(document).ready(function()
{
$(window).scroll(scrollMover);
});
If the scroll function is defined as
function scrollMover()
{
var offSets = getScrollXY();
document.getElementByID('divA').scrollLeft = offSets[0];
document.getElementByID('divB').scrollTop = offSets[1];
}
and
function getScrollXY()
{
var XOffset = 0, YOffset = 0;
if (typeof (window.pageYOffset) == 'number')
{
YOffset = window.pageYOffset;
XOffset = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
{
YOffset = document.body.scrollTop;
XOffset = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
{
YOffset = document.documentElement.scrollTop;
XOffset = document.documentElement.scrollLeft;
}
return [XOffset, YOffset];
}
Here's the Live Example , unfortunately, it's a little useless, since there are no scroll bars on the page !;)
: , ! fudgey.