Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Zoom reset fix
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 14, 2019
commit e07b6a7a77a5eb6ee38befbf9339ea2f1332482e
9 changes: 9 additions & 0 deletions src/components/Images.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default {
* Handle zooming
*
* @param {Event} event the scroll event
* @returns {null}
*/
updateZoom(event) {
event.stopPropagation()
Expand All @@ -130,6 +131,11 @@ export default {
? Math.min(this.zoomRatio + 0.2, 5) // prevent too big zoom
: Math.max(this.zoomRatio - 0.2, 1) // prevent too small zoom

// do not continue, img is back to its original state
if (newZoomRatio === 1) {
return this.resetZoom()
}

// calc how much the img grow from its current size
// and adjust the margin accordingly
const growX = this.width * newZoomRatio - this.width * this.zoomRatio
Expand All @@ -140,8 +146,11 @@ export default {
this.shiftY = this.shiftY + Math.round(-scrollPercY * growY)
this.zoomRatio = newZoomRatio
},

resetZoom() {
this.zoomRatio = 1
this.shiftX = 0
this.shiftY = 0
}
}
}
Expand Down