From 56d961d9fae69544f27ffffadabdfda3556a761a Mon Sep 17 00:00:00 2001 From: JimQing Date: Sun, 5 Jul 2020 11:31:03 +0800 Subject: [PATCH] fix: delete file --- src/scripts/sync-scroll.js | 23 ----------------------- src/view/CodemirrorEditor.vue | 15 ++++++++------- 2 files changed, 8 insertions(+), 30 deletions(-) delete mode 100644 src/scripts/sync-scroll.js 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;