refactor: 💡 improve image zoom

This commit is contained in:
Jin 2025-03-28 22:28:09 +01:00
parent df6c6647c7
commit 47a363be0f
2 changed files with 10 additions and 4 deletions

View File

@ -150,7 +150,7 @@ function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery<HTMLE
$renderedContent.append($img);
if (options.imageHasZoom) {
setTimeout(() => {
const initZoom = async () => {
const element = document.querySelector(`#${$img.attr("id")}`);
if (element) {
WheelZoom.create(`#${$img.attr("id")}`, {
@ -158,8 +158,11 @@ function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery<HTMLE
speed: 1.3,
zoomOnClick: false
});
} else {
requestAnimationFrame(initZoom);
}
}, 0);
};
initZoom();
}
imageContextMenuService.setupContextMenu($img);

View File

@ -54,7 +54,7 @@ class ImageTypeWidget extends TypeWidget {
this.$imageWrapper = this.$widget.find(".note-detail-image-wrapper");
this.$imageView = this.$widget.find(".note-detail-image-view").attr("id", `image-view-${utils.randomString(10)}`);
setTimeout(() => {
const initZoom = async () => {
const element = document.querySelector(`#${this.$imageView.attr("id")}`);
if (element) {
WheelZoom.create(`#${this.$imageView.attr("id")}`, {
@ -62,8 +62,11 @@ class ImageTypeWidget extends TypeWidget {
speed: 1.3,
zoomOnClick: false
});
} else {
requestAnimationFrame(initZoom);
}
}, 0);
};
initZoom();
imageContextMenuService.setupContextMenu(this.$imageView);