关于前端:滚动定位到指定位置

37次阅读

共计 576 个字符,预计需要花费 2 分钟才能阅读完成。

const flowDetailDivMenu = document.getElementById(“flowDetailDivMenu”);

  const approveListDivMenu = document.getElementById("approveListDivMenu");
  let detailBoxDivTop = flowDetailDivMenu ? flowDetailDivMenu.offsetTop : 0;
  let approveDivTop = approveListDivMenu ? approveListDivMenu.offsetTop : 0;

  setTimeout(() => {
    //-10 是为了上边留一点红色间距
    if (key === "detail") {
      window.scrollTo({top: detailBoxDivTop-10, // this.heightToTop(document.getElementById("flowDetailBox")),
        behavior: "instant"
      });
    } else if (key === "myCare") {window.scrollTo(0, 0);
    } 

    setTimeout(() => {window.addEventListener("scroll", this.myMenuTopScroll);
    }, 280);
  }, 10);

正文完
 0