This commit is contained in:
Vanessa 2023-11-10 10:51:34 +08:00
parent 5ae6f7c93f
commit 7579d3e2b3

View file

@ -5,6 +5,16 @@ import {onGet} from "../util/onGet";
import {isMobile} from "../../util/functions";
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
const getOffsetTop = (element: HTMLElement, topElement: HTMLElement) => {
let tempElement = element
let top = 0
while (topElement.contains(tempElement)) {
top += tempElement.offsetTop
tempElement = tempElement.offsetParent as HTMLElement
}
return top;
}
let getIndexTimeout: number;
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
let elementRect = element.getBoundingClientRect();
@ -25,8 +35,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
}
protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => {
if (item.parentElement.classList.contains("protyle-wysiwyg")) {
const headerTop = item.offsetTop + 43;
const headerTop = getOffsetTop(item, element) + 43;
const headerElement = item.querySelector(".av__row--header") as HTMLElement;
if (headerElement) {
if (headerTop < element.scrollTop && headerTop + headerElement.parentElement.clientHeight > element.scrollTop) {
@ -45,7 +54,6 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
footerElement.style.transform = "";
}
}
}
});
if (!protyle.element.classList.contains("block__edit") && !isMobile()) {