Skip to content

Instantly share code, notes, and snippets.

@reachtokish
Created August 20, 2020 05:09
Show Gist options
  • Save reachtokish/1ff9353726b17a8f8291b00a41d197af to your computer and use it in GitHub Desktop.
Save reachtokish/1ff9353726b17a8f8291b00a41d197af to your computer and use it in GitHub Desktop.
Synchronous scrolling
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