[new feature] ImagePreview: add lazyLoad prop (#2569)

This commit is contained in:
neverland 2019-01-20 13:35:15 +08:00 committed by GitHub
parent e45780dccc
commit 8bc8e99f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 25 deletions

View File

@ -9,7 +9,6 @@ export default sfc({
desc: String, desc: String,
thumb: String, thumb: String,
title: String, title: String,
centered: Boolean,
lazyLoad: Boolean, lazyLoad: Boolean,
thumbLink: String, thumbLink: String,
num: [Number, String], num: [Number, String],

View File

@ -10,10 +10,7 @@ const MIN_ZOOM = 1 / 3;
function getDistance(touches) { function getDistance(touches) {
return Math.sqrt( return Math.sqrt(
Math.abs( Math.abs((touches[0].clientX - touches[1].clientX) * (touches[0].clientY - touches[1].clientY))
(touches[0].clientX - touches[1].clientX) *
(touches[0].clientY - touches[1].clientY)
)
); );
} }
@ -22,6 +19,7 @@ export default sfc({
props: { props: {
images: Array, images: Array,
lazyLoad: Boolean,
asyncClose: Boolean, asyncClose: Boolean,
startPosition: Number, startPosition: Number,
showIndicators: Boolean, showIndicators: Boolean,
@ -67,8 +65,8 @@ export default sfc({
}; };
if (scale !== 1) { if (scale !== 1) {
style.transform = `scale3d(${scale}, ${scale}, 1) translate(${this style.transform = `scale3d(${scale}, ${scale}, 1) translate(${this.moveX / scale}px, ${this
.moveX / scale}px, ${this.moveY / scale}px)`; .moveY / scale}px)`;
} }
return style; return style;
@ -171,11 +169,7 @@ export default sfc({
if (this.moving || this.zooming) { if (this.moving || this.zooming) {
let stopPropagation = true; let stopPropagation = true;
if ( if (this.moving && this.startMoveX === this.moveX && this.startMoveY === this.moveY) {
this.moving &&
this.startMoveX === this.moveX &&
this.startMoveY === this.moveY
) {
stopPropagation = false; stopPropagation = false;
} }
@ -230,19 +224,23 @@ export default sfc({
show-indicators={this.showIndicators} show-indicators={this.showIndicators}
onChange={this.onChange} onChange={this.onChange}
> >
{images.map((item, index) => ( {images.map((image, index) => {
<SwipeItem> const props = {
<img class: bem('image'),
class={bem('image')} style: index === active ? this.imageStyle : null,
src={item} on: {
style={index === active ? this.imageStyle : null} touchstart: this.onTouchStart,
onTouchstart={this.onTouchStart} touchmove: this.onTouchMove,
onTouchmove={this.onTouchMove} touchend: this.onTouchEnd,
onTouchend={this.onTouchEnd} touchcancel: this.onTouchEnd
onTouchcancel={this.onTouchEnd} }
/> };
</SwipeItem> return (
))} <SwipeItem>
{this.lazyLoad ? <img v-lazy={image} {...props} /> : <img src={image} {...props} />}
</SwipeItem>
);
})}
</Swipe> </Swipe>
); );

View File

@ -60,6 +60,7 @@ setTimeout(() => {
| onClose | Close callback | `Function` | - | | onClose | Close callback | `Function` | - |
| asyncClose | Whether to enable async close | `Boolean` | `false` | | asyncClose | Whether to enable async close | `Boolean` | `false` |
| className | Custom className | `String | Array | Object` | - | | className | Custom className | `String | Array | Object` | - |
| lazyLoad | Whether to enable thumb lazy loadshould register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
### onClose Parematers ### onClose Parematers

View File

@ -9,6 +9,7 @@ const defaultConfig = {
loop: true, loop: true,
value: true, value: true,
className: '', className: '',
lazyLoad: false,
showIndex: true, showIndex: true,
asyncClose: false, asyncClose: false,
startPosition: 0, startPosition: 0,

View File

@ -68,6 +68,7 @@ setTimeout(() => {
| onClose | 关闭时的回调函数 | `Function` | - | 1.1.16 | | onClose | 关闭时的回调函数 | `Function` | - | 1.1.16 |
| asyncClose | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 | | asyncClose | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 |
| className | 自定义类名 | `String | Array | Object` | - | 1.5.2 | | className | 自定义类名 | `String | Array | Object` | - | 1.5.2 |
| lazyLoad | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 |
### onClose 回调参数 ### onClose 回调参数

View File

@ -5,6 +5,7 @@ export type ImagePreviewOptions = string[] | {
images: string[]; images: string[];
className?: any; className?: any;
startPosition?: number; startPosition?: number;
lazyLoad?: boolean;
showIndex?: boolean; showIndex?: boolean;
asyncClose?: boolean; asyncClose?: boolean;
showIndicators?: boolean; showIndicators?: boolean;