The problem of listening for scroll events in two boxes respectively


    leftEle.addEventListener("scroll", (e) =>{
         rightEle.scrollTop= e.target.scrollTop
    })
                
    rightEle.addEventListener("scroll", (e)=> {
        leftEle.scrollTop= e.target.scrollTop
    })
    

causes the mouse scroll to slide very slowly, so the scrollTop on both sides should contain each other"s scrolling at the same time. Is there any way to use both scrolls to isolate synchronization without restraining

Apr.14,2022

roughly understand what you mean. Do you want to scroll on the left and follow on the right? When you scroll on the right, do you follow the left? And then try not to influence each other?


wrote a demo , js code as follows:


var timeout = null;
window.addEventListener('scroll', function() {
    if(timeout !== null) clearTimeout(timeout);
    timeout = setTimeout(function() {
        var scrollTop = this.scrollY;
        console.log(scrollTop);
    }.bind(this), 500);
});
Menu