|
1 | 1 | import {BOTTOM_CONTENT_INTERSECTION, TOP_CONTENT_INTERSECTION} from "../consts/intersection-observer"; |
2 | 2 | import {action, computed, makeObservable, observable} from "mobx"; |
3 | 3 | import {ContentNavItem} from "../models/ContentNav"; |
4 | | -import {Scroll} from "./Scroll"; |
| 4 | +import { goToAnchor } from "../utils/scroll.utls"; |
5 | 5 |
|
6 | 6 | type ContentNavMetadata = { index: number, elementId: string, path: string, key: string }; |
7 | 7 | type SetId = string | null | undefined; |
@@ -99,20 +99,29 @@ export class ContentNavService { |
99 | 99 | private getLastMetadata = () => this.contentNavMetadataAll[this.contentNavMetadataAll.length - 1]; |
100 | 100 |
|
101 | 101 | private goToAnchor = (anchor: string) => { |
102 | | - function scrollHandler(event) { |
103 | | - window.removeEventListener("scroll", scrollHandler); |
104 | | - |
105 | | - window.scrollTo({ |
106 | | - left: 0, |
107 | | - }); |
108 | | - } |
109 | | - |
110 | | - window.addEventListener("scroll", scrollHandler); |
111 | | - |
112 | | - let sectionId = decodeURIComponent(anchor); |
113 | | - let element = document.getElementById<HTMLElement>(`${sectionId}`); |
114 | | - |
115 | | - element.scrollIntoView(); |
| 102 | + goToAnchor( anchor ); |
| 103 | + // function scrollHandler(event) { |
| 104 | + // window.removeEventListener("scroll", scrollHandler); |
| 105 | + // |
| 106 | + // window.scrollTo({ |
| 107 | + // left: 0, |
| 108 | + // }); |
| 109 | + // } |
| 110 | + // |
| 111 | + // window.addEventListener("scroll", scrollHandler); |
| 112 | + // |
| 113 | + // let sectionId = decodeURIComponent(anchor); |
| 114 | + // let element = document.getElementById(`${sectionId}`); |
| 115 | + // |
| 116 | + // console.log( `SCROLL_POSITION` ); |
| 117 | + // element.scrollIntoView(); |
| 118 | + // |
| 119 | + // let clientRect = element.getBoundingClientRect(); |
| 120 | + // |
| 121 | + // window.scrollTo( { |
| 122 | + // top: window.pageYOffset + clientRect.top, |
| 123 | + // left: 0 |
| 124 | + // } ) |
116 | 125 | } |
117 | 126 |
|
118 | 127 | private getPrevAnchor = (currentelementId: string) => { |
|
0 commit comments