From e6d4f331a81383e07039198a15c1d570ebc76f35 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 11 Apr 2019 14:38:46 +0800 Subject: [PATCH] =?UTF-8?q?[new=20feature]=20ImagePreview:=20add=20max-zoo?= =?UTF-8?q?m=E3=80=81min-zoom=20prop=20(#3133)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/image-preview/ImagePreview.js | 12 +++++++++--- packages/image-preview/en-US.md | 2 ++ packages/image-preview/index.js | 2 ++ packages/image-preview/zh-CN.md | 2 ++ types/image-preview.d.ts | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/image-preview/ImagePreview.js b/packages/image-preview/ImagePreview.js index 7f7f3df03..9d9739fc6 100644 --- a/packages/image-preview/ImagePreview.js +++ b/packages/image-preview/ImagePreview.js @@ -5,8 +5,6 @@ import Swipe from '../swipe'; import SwipeItem from '../swipe-item'; const [sfc, bem] = use('image-preview'); -const MAX_ZOOM = 3; -const MIN_ZOOM = 1 / 3; function getDistance(touches) { return Math.sqrt( @@ -36,6 +34,14 @@ export default sfc({ type: Boolean, default: true }, + minZoom: { + type: Number, + default: 1 / 3 + }, + maxZoom: { + type: Number, + default: 3 + }, overlayClass: { type: String, default: 'van-image-preview__overlay' @@ -160,7 +166,7 @@ export default sfc({ if (this.zooming && touches.length === 2) { const distance = getDistance(touches); const scale = (this.startScale * distance) / this.startDistance; - this.scale = range(scale, MIN_ZOOM, MAX_ZOOM); + this.scale = range(scale, this.minZoom, this.maxZoom); } }, diff --git a/packages/image-preview/en-US.md b/packages/image-preview/en-US.md index 97b67bae1..49fcfbb6b 100644 --- a/packages/image-preview/en-US.md +++ b/packages/image-preview/en-US.md @@ -61,6 +61,8 @@ setTimeout(() => { | asyncClose | Whether to enable async close | `Boolean` | `false` | | className | Custom className | `String | Array | Object` | - | | lazyLoad | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` | +| maxZoom | Max zoom | `Number` | `3` | +| minZoom | Min zoom | `Number` | `1/3` | ### onClose Parematers diff --git a/packages/image-preview/index.js b/packages/image-preview/index.js index 9625a717e..96e80a22e 100644 --- a/packages/image-preview/index.js +++ b/packages/image-preview/index.js @@ -8,6 +8,8 @@ const defaultConfig = { images: [], loop: true, value: true, + minZoom: 1 / 3, + maxZoom: 3, className: '', lazyLoad: false, showIndex: true, diff --git a/packages/image-preview/zh-CN.md b/packages/image-preview/zh-CN.md index 59f8b306c..b5f9e8744 100644 --- a/packages/image-preview/zh-CN.md +++ b/packages/image-preview/zh-CN.md @@ -69,6 +69,8 @@ setTimeout(() => { | asyncClose | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 | | className | 自定义类名 | `String | Array | Object` | - | 1.5.2 | | lazyLoad | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 | +| maxZoom | 手势缩放时,最大缩放比例 | `Number` | `3` | 1.6.14 | +| minZoom | 手势缩放时,最小缩放比例 | `Number` | `1/3` | 1.6.14 | ### onClose 回调参数 diff --git a/types/image-preview.d.ts b/types/image-preview.d.ts index 9a08f05c6..c2ff9b369 100644 --- a/types/image-preview.d.ts +++ b/types/image-preview.d.ts @@ -3,6 +3,8 @@ import { VanPopupMixin } from './mixins/popup'; export type ImagePreviewOptions = string[] | { loop?: boolean; images: string[]; + maxZoom?: number; + minZoom?: number; className?: any; startPosition?: number; lazyLoad?: boolean;