I'm trying to coordinate the scrolling of two divs, similar to this question, but both of my divs are scrollable (whereas in the question one of the divs is the control and the other the slave, the user can scroll either and other re-scrolls accordingly).
My jQuery/JavaScript is:
// as the user scrolls one div, we also scroll the other
var scrolldiv1 = $('#scrolldiv1'),
scrolldiv2 = $('#scrolldiv2');
scrolldiv1.scroll(function () { scrolldiv2.scrollTop(scrolldiv1.scrollTop()); });
scrolldiv2.scroll(function () { scrolldiv1.scrollTop(scrolldiv2.scrollTop()); });
When the user scrolls a div using the element's scrollbars, everything works beautifully. When the user scrolls a div using his or her mouse wheel while hovering over the element, the divs stay synchronized but scrolling is VERY sluggish. I suspect both events are firing and the positions fight each other.
Does anyone have any suggestions on what I can do to make wheel-scrolling just as snappy as the scrollbar-initiated scrolling?
Thanks in advance!