How to synchronize two scrollbars for divs
css, javascript
Solution
The javascript in this is what you need really, but I added the html so you can see it in action.
$("#div1").scroll(function () {
$("#div2").scrollTop($("#div1").scrollTop());
$("#div2").scrollLeft($("#div1").scrollLeft());
});
$("#div2").scroll(function () {
$("#div1").scrollTop($("#div2").scrollTop());
$("#div1").scrollLeft($("#div2").scrollLeft());
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<div id="div1" style="float:left;overflow:auto;height:100px;width:200px;">
<p>lulz</p>
<p>lulz</p>
<p>lulz</p>
<p>lulz</p>
</div>
<div id="div2" style="float:right;overflow:auto;height:100px;width:200px;">
<p>lulz</p>
<p>lulz</p>
<p>lulz</p>
<p>lulz</p>
</div>
Problem
I have this code for file compares: http://jsfiddle.net/CrN6X/ Now it does what I need: - One big div that scrolls only vertically - Two smaller dives that scroll only horizontally This way I can compare my files pretty easy, but I have one problem: the bottom scrollbars are accessable only when I scroll all the way down. How can I make them float or move the scrollbar to another div, that can bee seen always, so that I don't need to scroll down the other div all the way to the bottom to access them?