I have an HTML layout based on tabs (say 5). In each tab I load an iframe. The iframe contents are variations of one another that the user can compare by switching tabs.
How can I, in javascript, synchronize the scrolling of all iframes vertically and horizontally? In other words, scrolling in one iframe should scroll by the same amount all other iframes, allowing the user to compare the same data.
Bonus points: iframe content is loaded only when the user opens the tab for the first time. So newly opened iframes should directly scroll to the same place as already opened iframes.
Thanks.
To synchronise an arbitrary number of elements use the following code:
Using this is SUPER simple. Lets say you have several divs defined as:
To synchronize the scrollbars’ on all divs with the class scrollDiv all you need to write is:
Source: http://blogs.msdn.com/b/matt/archive/2009/03/19/synchronizing-scrollbars-using-jquery.aspx
I synchronize overflowed div's using code like this:
Accepted solution works only if divs have the same width. If not, it causes an infinite loop: #div1 scrolls #div2, then #div2's scroll event scrolls #div1 etc :)
Edited solution:
I think this answer can fix the infinite loop.
While this works for divs, it does not work for iframes.
Here's what you can do,
With jQuery's scroll event, you should be able to synchronize them.
Edit: No plugins required. Here's the code that worked for me: