Skip to content

Commit

Permalink
fix(imageviewer): 图片预览拖拽问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fennghuang committed Sep 27, 2023
1 parent d595c98 commit 26b7669
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/image-viewer/image-viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<t-image
:src="image"
:style="`${imageTransitionDuration}; ${index === touchIndex ? `transform: ${imageTransform}` : ''}`"
:on-load="({ e }) => onLoad(e, index)"
/>
</t-swiper-item>
</t-swiper>
Expand Down Expand Up @@ -94,6 +95,7 @@ export default defineComponent({
const disabled = ref(false);
const rootRef = ref();
const imagesSize = reactive({});
const closeNode = computed(() =>
renderTNode(internalInstance, 'close-btn', {
Expand Down Expand Up @@ -141,6 +143,11 @@ export default defineComponent({
}
};
const onLoad = (e: Event, index: number) => {
const { height } = e.target as HTMLImageElement;
imagesSize[index] = { height };
};
const maxDraggedX = computed(() => {
const rootOffsetWidth = rootRef.value?.offsetWidth || 0;
const scaledWidth = state.scale * rootOffsetWidth;
Expand All @@ -149,8 +156,9 @@ export default defineComponent({
const maxDraggedY = computed(() => {
const rootOffsetHeight = rootRef.value?.offsetHeight || 0;
const scaledHeight = state.scale * rootOffsetHeight;
return Math.max(0, (scaledHeight - rootOffsetHeight) / 2);
const currentImageScaledHeight = state.scale * (imagesSize?.[currentIndex.value]?.height || 0);
if (currentImageScaledHeight <= rootOffsetHeight) return 0;
return Math.max(0, (currentImageScaledHeight - rootOffsetHeight) / 2);
});
let fingerNum: number;
Expand Down Expand Up @@ -338,6 +346,7 @@ export default defineComponent({
onTouchStart,
onTouchMove,
onTouchEnd,
onLoad,
};
},
});
Expand Down

0 comments on commit 26b7669

Please sign in to comment.