I have these two scroll events firing on dom.ready that synchronize scrolling between my main document and a div's horizontal scrollbar. All works as expected - in all browsers – except for some annoying jank in IE when content gets a little heavy.
Heads-up: the jsScroll0 and jsScroll1 flags stop either scrollbar from locking due to an infinite loop scenario upon each scrollbar trying to set each other’s values.
$(document).ready(function () {
//-------------------------------------------
// S y n c t w o S c r o l l b a r s
//-------------------------------------------
// Ver.01
//Basically the same as my concept:
//http://stackoverflow.com/questions/762274/how-to-synchronize-scrolling-positions-for-several-iframes
//Sync's scrollbars, and the flags fix infinite loop.
//ALSO:
//http://stackoverflow.com/questions/18952623/synchronized-scrolling-using-jquery
//has % for scrollbars of different sizes
var jsScroll0;
var jsScroll1;
var windows = [$(document), $('#scrollP')];
windows[0].on('scroll.scrollInTheSameTime', function () {
if (jsScroll1 === true) {
jsScroll1 = false;
return;
}
jsScroll0 = true;
windows[1].scrollLeft(windows[0].scrollTop());
});
windows[1].on('scroll.scrollInTheSameTime', function () {
if (jsScroll0 === true) {
jsScroll0 = false;
return;
}
jsScroll1 = true;
windows[0].scrollTop(windows[1].scrollLeft());
});
});
I suppose the crux of the matter is why IE struggles and the other's don't? Does IE handle scrolling / fire events completely differently?
ATTEMPT: I tried getting rid of the jquery overhead by using document.documentElement.scrollTop / and accessing the div via document.getElementById('scrollP') - but it didn't make a difference.