跳转到指定页面的指定位置

92 阅读1分钟
const scrollTo = (behavior = "smooth", block = "start", inline = "nearest", item) => {
  // 跳转到指定页面
  // pageIns.value.scrollIntoView({ behavior, block, inline });
  if (item) {
    console.log(item);
    /* 数据示例
    {
        "key": 979,
        "label": "第五条 抵押财产的保险",
        "pageIndex": 7,
        "position": {
            "x": 0.1914,
            "y": 0.1983
        },
        "children": []
    }
    */
    const targetPos = document.createElement("div");
    targetPos.style.width = "100px";
    targetPos.style.height = "100px";
    targetPos.style.position = "absolute";
    targetPos.style.top = item.position.y * 100 + "%";
    // pageIns是指定页面的ref
    pageIns.value.appendChild(targetPos);
    console.log("targetPos", targetPos);
    // 跳转到指定页面的指定位置
    targetPos.scrollIntoView({behavior: "smooth"});
    pageIns.value.removeChild(targetPos)
  }
};