diff --git a/src/image-preview/ImagePreviewItem.js b/src/image-preview/ImagePreviewItem.js index 9937eafa9..4a296c2a8 100644 --- a/src/image-preview/ImagePreviewItem.js +++ b/src/image-preview/ImagePreviewItem.js @@ -38,6 +38,7 @@ export default { moveY: 0, moving: false, zooming: false, + vertical: false, displayWidth: 0, displayHeight: 0, }; @@ -155,7 +156,6 @@ export default { /* istanbul ignore else */ if (this.moving || this.zooming) { - stopPropagation = true; if ( @@ -220,12 +220,14 @@ export default { const windowRatio = windowHeight / windowWidth; const imageRatio = naturalHeight / naturalWidth; - if (imageRatio < windowRatio) { - this.displayWidth = windowWidth; - this.displayHeight = windowWidth * imageRatio; - } else { + this.vertical = imageRatio > windowRatio; + + if (this.vertical) { this.displayWidth = windowHeight / imageRatio; this.displayHeight = windowHeight; + } else { + this.displayWidth = windowWidth; + this.displayHeight = windowWidth * imageRatio; } }, }, @@ -236,11 +238,11 @@ export default { }; return ( - +
-
-
-
+
+
+
1 / 3
diff --git a/src/image-preview/test/index.spec.js b/src/image-preview/test/index.spec.js index b3485c74e..e02d8e89f 100644 --- a/src/image-preview/test/index.spec.js +++ b/src/image-preview/test/index.spec.js @@ -139,6 +139,7 @@ test('double click', async () => { const swipe = instance.$el.querySelector('.van-swipe-item'); triggerDrag(swipe, 0, 0); triggerDrag(swipe, 0, 0); + await later(); expect(onScale).toHaveBeenCalledWith({ index: 0, scale: 2,