[improvement] ImagePreview: support dbclick zoom (#3839)

This commit is contained in:
cesc fabregas
2019-07-14 14:07:52 +08:00
committed by neverland
parent 7b9331aee4
commit f50dc30484
2 changed files with 49 additions and 11 deletions

View File

@@ -77,7 +77,8 @@ export default createComponent({
moveY: 0,
moving: false,
zooming: false,
active: 0
active: 0,
doubleClickTimer: null
};
},
@@ -120,16 +121,26 @@ export default createComponent({
// prevent long tap to close component
if (deltaTime < 300 && offsetX < 10 && offsetY < 10) {
const index = this.active;
if (!this.doubleClickTimer) {
this.doubleClickTimer = setTimeout(() => {
const index = this.active;
this.resetScale();
this.$emit('close', {
index,
url: this.images[index]
});
this.resetScale();
this.$emit('close', {
index,
url: this.images[index]
});
if (!this.asyncClose) {
this.$emit('input', false);
if (!this.asyncClose) {
this.$emit('input', false);
}
this.doubleClickTimer = null;
}, 300);
} else {
clearTimeout(this.doubleClickTimer);
this.doubleClickTimer = null;
this.toggleScale();
}
}
},
@@ -228,6 +239,14 @@ export default createComponent({
this.scale = 1;
this.moveX = 0;
this.moveY = 0;
},
toggleScale() {
const scale = this.scale > 1 ? 1 : 2;
this.scale = scale;
this.moveX = 0;
this.moveY = 0;
}
},