From b771349e3b950d129188f07471e93596de299276 Mon Sep 17 00:00:00 2001 From: WeepingDogel Date: Mon, 30 Jan 2023 00:34:51 +0800 Subject: [PATCH] Fix the problem of the Uploader and Comment Action. --- flaskr/static/js/Main.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/flaskr/static/js/Main.js b/flaskr/static/js/Main.js index 4a53cdc..a8aa63d 100644 --- a/flaskr/static/js/Main.js +++ b/flaskr/static/js/Main.js @@ -63,12 +63,32 @@ function avatarChecking(){ } } +var winX = null; +var winY = null; +window.addEventListener('scroll', +function () { + if (winX !== null && winY !== null) { + window.scrollTo(winX, winY); + } +}); + +function disableWindowScroll() { + winX = window.scrollX; winY = window.scrollY; +} + +function enableWindowScroll() { + winX = null; winY = null; +} + + function displayUploader(){ var uploader = document.getElementById('mask'); if(uploader.style.display == "block"){ uploader.style.display = "none"; + enableWindowScroll(); }else{ uploader.style.display = "block"; + disableWindowScroll(); } } @@ -112,13 +132,10 @@ function ReplyTo(numID){ scrollTo(0,0); let ReplyTo = document.getElementsByClassName("Reply")[numID - 1]; let ReplyToUser = document.getElementsByClassName("ReplyToUser")[numID - 1]; - let ReplyToDate = document.getElementsByClassName("ReplyToDate")[numID - 1]; let InputValueOfReplyTo = document.getElementById("ReplyTo"); let InputValueOfReplyToUser = document.getElementById("ReplyToUser"); - let InputValueOfReplyToDate = document.getElementById("ReplyToDate"); InputValueOfReplyTo.value = ReplyTo.value; InputValueOfReplyToUser.value = ReplyToUser.innerText; - InputValueOfReplyToDate.value = ReplyToDate.innerText; SendComments(); } @@ -128,8 +145,10 @@ function SendComments() { var Commenter = document.getElementById('mask'); if(Commenter.style.display == "block"){ Commenter.style.display = "none"; + enableWindowScroll(); }else{ Commenter.style.display = "block"; + disableWindowScroll(); } }