Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

Image zooming in viewerjs causes noticeable lag. This replaces it with a performant custom implementation and enhances the existing PhotoViewer component.

Changes

PhotoViewer.vue

  • Replaced binary zoom toggle (fixed 1.5x) with continuous zoom (1x-4x)
  • Added pinch-to-zoom, wheel zoom, and drag-to-pan
  • Used CSS transforms with will-change: transform for GPU acceleration
  • Disabled swiper touch events during image drag to prevent conflicts

New ImageViewer.vue

  • Lightweight replacement for viewerjs library
  • Same gesture support as PhotoViewer (pinch, wheel, drag, double-click)
  • Removes ~50KB gzipped dependency

Implementation Example

// Transform state per image
const imageTransforms = ref<Map<number, ImageTransform>>(new Map());

interface ImageTransform {
  scale: number;      // 1x-4x range
  translateX: number; // Pan offset
  translateY: number;
}

// Smooth GPU-accelerated transforms
const imageStyle = computed(() => ({
  transform: `translate(${tx}px, ${ty}px) scale(${scale})`,
  transition: isDragging ? 'none' : 'transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  willChange: 'transform'
}));

All zoom/pan operations use CSS transforms to avoid layout recalculation.

Original prompt

This section details on the original issue you should resolve

<issue_title>viewer js 实现的图片预览器进行图片缩放卡顿</issue_title>
<issue_description>是否存在性能优化的点?如果没有是否可以自己实现一个类似 viewer js 的库,功能是其子集即可</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Oct 26, 2025
@vercel
Copy link

vercel bot commented Oct 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
shellraining-blog Error Error Oct 26, 2025 5:42am

- Replace simple toggle zoom with smooth, interactive zoom/pan system
- Add pinch-to-zoom gesture support for touch devices
- Add mouse wheel zooming for desktop
- Add drag-to-pan when image is zoomed
- Use CSS transforms with will-change for GPU acceleration
- Smooth transitions with cubic-bezier easing
- Scale range: 1x to 4x for better control
- Disable swiper touch when dragging zoomed images

Co-authored-by: shellRaining <[email protected]>
- Create custom ImageViewer component with optimized zoom/pan
- Remove viewerjs dependency to reduce bundle size
- Implement same touch/mouse gestures as PhotoViewer
- Support pinch-to-zoom, double-click zoom, wheel zoom
- Add smooth drag-to-pan when zoomed
- Simpler and more performant than viewerjs library

Co-authored-by: shellRaining <[email protected]>
@shellRaining
Copy link
Owner

是 Viewer.vue 的滚动缩放效果不好

- Move drag state variables into setup function as refs
- Save and restore original body overflow value
- Update zoom hint text for clarity

Co-authored-by: shellRaining <[email protected]>
Copilot AI changed the title [WIP] Optimize image viewer performance for scaling Replace viewerjs with optimized custom image viewer implementation Oct 26, 2025
Copilot AI requested a review from shellRaining October 26, 2025 05:43
Copilot finished work on behalf of shellRaining October 26, 2025 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

viewer js 实现的图片预览器进行图片缩放卡顿

2 participants