fix: 修复认证文件滚轮缩放
This commit is contained in:
@@ -32,6 +32,43 @@ function getImageSize(url: string): Promise<{ width: number; height: number }> {
|
||||
});
|
||||
}
|
||||
|
||||
function bindWheelZoom(lightbox: PhotoSwipeLightbox): void {
|
||||
lightbox.on('wheel', (event: any) => {
|
||||
const originalEvent = event?.originalEvent as WheelEvent | undefined;
|
||||
const pswp = lightbox.pswp as any;
|
||||
const slide = pswp?.currSlide;
|
||||
if (!originalEvent || !slide?.isZoomable?.()) return;
|
||||
|
||||
event.preventDefault();
|
||||
originalEvent.preventDefault();
|
||||
originalEvent.stopPropagation();
|
||||
|
||||
const zoomLevels = slide.zoomLevels || {};
|
||||
const current = slide.currZoomLevel || zoomLevels.initial || 1;
|
||||
const initial = zoomLevels.initial || current || 1;
|
||||
const min = zoomLevels.min || initial;
|
||||
const max = Math.max(zoomLevels.max || 0, initial * 6, 4);
|
||||
|
||||
let zoomFactor = -originalEvent.deltaY;
|
||||
if (originalEvent.deltaMode === 1) {
|
||||
zoomFactor *= 0.05;
|
||||
} else {
|
||||
zoomFactor *= originalEvent.deltaMode ? 1 : 0.002;
|
||||
}
|
||||
const nextZoom = Math.min(max, Math.max(min, current * 2 ** zoomFactor));
|
||||
|
||||
slide.zoomTo(
|
||||
nextZoom,
|
||||
{
|
||||
x: originalEvent.clientX,
|
||||
y: originalEvent.clientY,
|
||||
},
|
||||
0,
|
||||
true,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function openMediaViewer(items: MediaViewerItem[], index = 0): Promise<void> {
|
||||
const list = (items || []).filter((item) => item.url);
|
||||
if (!list.length) return;
|
||||
@@ -61,6 +98,8 @@ export async function openMediaViewer(items: MediaViewerItem[], index = 0): Prom
|
||||
wheelToZoom: true,
|
||||
});
|
||||
|
||||
bindWheelZoom(lightbox);
|
||||
|
||||
lightbox.on('contentLoad', (event: any) => {
|
||||
const { content } = event;
|
||||
if (content?.data?.type !== 'video') return;
|
||||
|
||||
Reference in New Issue
Block a user