mirror of
https://github.com/doocs/md.git
synced 2024-12-01 06:42:23 +08:00
c3b04aac21
代码优化
24 lines
655 B
JavaScript
24 lines
655 B
JavaScript
// 左右栏同步滚动
|
|
$(document).ready(() => {
|
|
let timeout;
|
|
$('div.CodeMirror-scroll, #preview').on("scroll", function callback() {
|
|
clearTimeout(timeout);
|
|
|
|
let source = $(this),
|
|
target = $(source.is("#preview") ? 'div.CodeMirror-scroll' : '#preview');
|
|
|
|
target.off("scroll");
|
|
|
|
let source0 = source[0];
|
|
let target0 = target[0];
|
|
|
|
let percentage = source0.scrollTop / (source0.scrollHeight - source0.offsetHeight);
|
|
let height = percentage * (target0.scrollHeight - target0.offsetHeight);
|
|
target0.scrollTo(0, height);
|
|
|
|
timeout = setTimeout(() => {
|
|
target.on("scroll", callback);
|
|
}, 100);
|
|
});
|
|
});
|