Created
August 20, 2020 05:09
-
-
Save reachtokish/1ff9353726b17a8f8291b00a41d197af to your computer and use it in GitHub Desktop.
Synchronous scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let isSyncingLeftScroll = false; | |
let isSyncingRightScroll = false; | |
document.getElementById('input_table').addEventListener('scroll', e => { | |
if (!isSyncingLeftScroll) { | |
isSyncingRightScroll = true; | |
document.getElementById('output_table').scrollTop = e.target.scrollTop; | |
} | |
isSyncingLeftScroll = false; | |
}, false); | |
document.getElementById('output_table').addEventListener('scroll', e => { | |
if (!isSyncingRightScroll) { | |
isSyncingLeftScroll = true; | |
document.getElementById('input_table').scrollTop = e.target.scrollTop; | |
} | |
isSyncingRightScroll = false; | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment