i have 3 divs with scrollbars. If i scroll in div 1 i want to scroll div 2 and 3 in the opposite direction. The distance scrolled should be half the distance of div 1.
This is what i have now (small part, rest is in jsfiddle), which works for 1 div.
$("#textBox1").scroll(function () {
console.log("scroll 1");
var offset = $("#textBox1").scrollTop() - scrollPosTBox1;
var half_offset = offset/2.0;
disable1 = true;
if(disable2 == false) {
$("#textBox2").scrollTop(scrollPosTBox2 - half_offset);
}
if(disable3 == false) {
$("#textBox3").scrollTop(scrollPosTBox3 - half_offset);
}
disable1 = false;
});
However, if i try to get the same for the other 2 divs then i can't scroll anything anymore. This is because div 1 triggers div 2 and div 2 triggers back to div 1 for example. I tried to fix this with the disable code but it doesn't help.
Can someone help me?
No disrespect to @EmreErkan and @Simon for their effort. Here's a no-click version of this.
Fiddle
Finally got a dynamic solution for this, was more complex than I thought but I think I got it:
http://jsfiddle.net/XmYh5/14/
You can use a variable to determine active textbox with
.mousedown()
and do the trick if it's active;You can check your updated jsFiddle here.