Working on this page at the moment
https://www.cliquenext.com/sandbox.php
We have two div columns. #mainpage (to the right) and #sidebar to the left.
The aim is that if I scroll in the right column, the left scrolls too. If I scroll in the left column, the right scrolls too. Both at the same time.
When I use $(window).ScrollTop - it works fine. When I use $("#sidebar").Scrolltop - it doesnt fire.
The following code works scrolling #mainpage when scrolling #sidebar.
$("#sidebar").scroll(function(event){
event.preventDefault();
var st = $(this).scrollTop();
if (st > lastScrollTop){
// downscroll code
var y = $(window).scrollTop(); //your current y position on the page
$(window).scrollTop(y+10);
} else {
// upscroll code
var y = $(window).scrollTop(); //your current y position on the page
$(window).scrollTop(y-10);
}
lastScrollTop = st;
});
The following code doesn't work. When scrolling on #mainpage the #sidebar should scroll too. But its not.
$("#mainpage").scroll(function(event){
event.preventDefault();
var st2 = $(this).scrollTop();
if (st2 > lastinfoscroll){
// downscroll code
var y = $("#sidebar").scrollTop(); //your current y position on the page
$("#sidebar").scrollTop(y+10);
} else {
// upscroll code
var y = $("#sidebar").scrollTop(); //your current y position on the page
$("#sidebar").scrollTop(y-10);
}
lastinfoscroll = st2;
});
I would like to detect when one of the divs are being scrolled, and then scroll both divs.
I can't seem to figure out how to get it fire on divs so that I can scroll both divs at once. Been stuck on this problem for ages. Also don't want to use Animate.
Any help would be greatly appreciated. Cheers