To achieve the same effect on the right column as you did with the left, simply follow these steps:
$("#right").on("scroll", function () {
var scrolledleft = parseInt($("#right").scrollTop()) * -1;
console.log(scrolledleft + scrolledright)
$("#left").scrollTop(scrolledleft + scrolledright)
});
Check out this JSFiddle for a live example.
Note: Firefox might trigger the scroll event when using scrollTop programmatically. To prevent unwanted scrolling interactions between the two columns, you can utilize an additional variable called preventEvent
:
var preventEvent = false;
// Event listener for left column scrolling
$("#left").on("scroll", function (e) {
if(preventEvent) {
preventEvent = false;
return;
}
preventEvent = true;
var scrolledleft = parseInt($("#left").scrollTop()) * -1;
$("#right").scrollTop(scrolledleft + scrolledright);
});
// Event listener for right column scrolling
$("#right").on("scroll", function (e) {
if(preventEvent) {
preventEvent = false;
return;
}
preventEvent = true;
var scrolledleft = parseInt($("#right").scrollTop()) * -1;
$("#left").scrollTop(scrolledleft + scrolledright)
});
Here's an updated JSFiddle to illustrate the implementation.