2021年1月24日星期日

JavaScript RefrenceError: Function not defined (when it clearly has been)

I have this Javascript script that calls a function called scrollUp() that auto-scrolls to a portion of my webpage if the user scrolls up or down. When I scroll up, it says "ReferenceError: scrollUp is not defined". Strangely enough, the ScrollDown() function works fine.

function scroll() {    var origPos = wPos.position;    var newPos = window.scrollY;    if (newPos - origPos < 0) {      //Scrolled down      wPos.scrollDown();    } else {      //Scrolled up      wPos.scrollUp();    }    wPos.update();     }    class WindowPos {      constructor(window) {      this.position = window?.scrollY;    }      update() {      this.position = window.scrollY;    }      scrollUp() {      window.scrollBy(0, 770);      scrolldelay = setTimeout(scrollUp, 10);    }      scrollDown() {      window.scrollBy(0, -770);      scrolldelay = setTimeout(scrollDown, 10);    }    }    var wPos = new WindowPos();  window.onscroll = scroll;  
https://stackoverflow.com/questions/65878463/javascript-refrenceerror-function-not-defined-when-it-clearly-has-been January 25, 2021 at 11:06AM

没有评论:

发表评论