diff --git a/src/scripts/sync-scroll.js b/src/scripts/sync-scroll.js deleted file mode 100644 index 611ce62..0000000 --- a/src/scripts/sync-scroll.js +++ /dev/null @@ -1,23 +0,0 @@ -// 左右栏同步滚动 -$(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); - }); -}); diff --git a/src/view/CodemirrorEditor.vue b/src/view/CodemirrorEditor.vue index 296a0ea..451b831 100644 --- a/src/view/CodemirrorEditor.vue +++ b/src/view/CodemirrorEditor.vue @@ -60,7 +60,7 @@ import { } from '../scripts/util' require('codemirror/mode/javascript/javascript') -import $ from 'jquery' +// import $ from 'jquery' import config from '../scripts/config' import {mapState, mapMutations} from 'vuex'; export default { @@ -201,10 +201,12 @@ export default { }, // 左右栏同步滚动 leftAndRightScroll() { - $('#preview').on('scroll', function callback() { - clearTimeout(this.timeout) + const _this = this; - let source = $(this) + document.getElementById('preview').addEventListener("scroll", function callback() { + clearTimeout(_this.timeout) + + let source = $(_this) let target = $(source.is('#preview') ? 'div.CodeMirror-scroll' : '#preview') target.off('scroll') @@ -216,14 +218,13 @@ export default { let height = percentage * (target0.scrollHeight - target0.offsetHeight) target0.scrollTo(0, height) - this.timeout = setTimeout(() => { + _this.timeout = setTimeout(() => { target.on('scroll', callback) }, 100) - }) + }, true); }, onEditorRefresh() { this.editorRefresh(); - // setTimeout(()=> PR.prettyPrint(), 0); }, endCopy() { this.backLight = false;