Vanessa
2026-05-04 12:53:14 +08:00
parent b3e26feedf
commit 76e7ecb19c
3 changed files with 7 additions and 35 deletions
-29
View File
@@ -18,37 +18,8 @@ import {Editor} from "../../editor";
import {hideTooltip} from "../../dialog/tooltip";
export const globalTouchStart = (event: TouchEvent) => {
// 文档背景位置调整
const target = event.target as HTMLElement;
const backgroundElement = hasClosestByClassName(target, "protyle-background");
if (backgroundElement && target.tagName === "IMG" && backgroundElement.firstElementChild.querySelector(".protyle-icons").classList.contains("fn__none")) {
const contentElement = hasClosestByClassName(target, "protyle-content", true);
if (!contentElement) {
return false;
}
contentElement.style.overflow = "hidden";
const y = event.touches[0].clientY;
const height = (target as HTMLImageElement).naturalHeight * target.clientWidth / (target as HTMLImageElement).naturalWidth - target.clientHeight;
let originalPositionY = parseFloat(target.style.objectPosition.substring(7)) || 50;
if (target.style.objectPosition.endsWith("px")) {
originalPositionY = -parseInt(target.style.objectPosition.substring(7)) / height * 100;
}
const documentSelf = document;
documentSelf.ontouchmove = (moveEvent) => {
target.style.objectPosition = `center ${((y - moveEvent.touches[0].clientY) / height * 100 + originalPositionY).toFixed(2)}%`;
};
documentSelf.ontouchend = () => {
contentElement.style.overflow = "";
documentSelf.ontouchmove = null;
documentSelf.ontouchstart = null;
documentSelf.ondragstart = null;
documentSelf.onselectstart = null;
documentSelf.onselect = null;
};
event.stopImmediatePropagation();
return true;
}
if (backgroundElement) {
if (backgroundElement.classList.contains("protyle-background--enable")) {
backgroundElement.classList.add("protyle-background--mobileshow");
+4 -5
View File
@@ -512,8 +512,8 @@ export class Background {
};
const onMouseUp = (upEvent: MouseEvent) => {
window.removeEventListener("mousemove", onMouseMove);
window.removeEventListener("mouseup", onMouseUp, true);
document.onmousemove = null;
document.onmouseup = null;
document.body.style.cursor = "";
if (isDragging) {
@@ -544,9 +544,8 @@ export class Background {
}
};
// 使用捕获阶段监听 mouseup,确保能第一时间拦截拖拽后的 click
window.addEventListener("mousemove", onMouseMove);
window.addEventListener("mouseup", onMouseUp, true);
document.onmousemove = (e) => onMouseMove(e as MouseEvent);
document.onmouseup = (e) => onMouseUp(e as MouseEvent);
});
}
+3 -1
View File
@@ -76,7 +76,9 @@ const handleManualTouchStart = (e: TouchEvent) => {
!target.closest(".av__widthdrag") &&
!target.closest(".av__drag-fill") &&
!target.closest(".protyle-action__drag") &&
!target.closest(".table__resize")) return;
!target.closest(".table__resize") &&
!target.closest(".protyle-background__img") &&
!target.closest(".b3-chip")) return;
const touch = e.touches[0];
dispatchSyntheticMouse("mousedown", touch.clientX, touch.clientY, target);