+ // Scroll sync
+ let inputScrollHeight,
+ inputHeight,
+ displayScrollHeight,
+ displayHeight;
+
+ function setScrollHeights() {
+ inputScrollHeight = input[0].scrollHeight;
+ inputHeight = input.height();
+ displayScrollHeight = display[0].scrollHeight;
+ displayHeight = display.height();
+ }
+
+ setTimeout(() => {
+ setScrollHeights();
+ }, 200);
+ window.addEventListener('resize', setScrollHeights);
+ let scrollDebounceTime = 800;
+ let lastScroll = 0;
+ input.on('scroll', event => {
+ let now = Date.now();
+ if (now - lastScroll > scrollDebounceTime) {
+ setScrollHeights()
+ }
+ let scrollPercent = (input.scrollTop() / (inputScrollHeight-inputHeight));
+ let displayScrollY = (displayScrollHeight - displayHeight) * scrollPercent;
+ display.scrollTop(displayScrollY);
+ lastScroll = now;
+ });
+