Skip to content

Commit

Permalink
Merge pull request #1887 from nextcloud/enh/image-zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Aug 27, 2023
2 parents 3e7dba4 + 1dbc066 commit 2f3384f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions src/components/Images.vue
Expand Up @@ -36,10 +36,10 @@
}"
:src="data"
:style="{
marginTop: (shiftY * 2) + 'px',
marginLeft: (shiftX * 2) + 'px',
maxHeight: zoomRatio * 100 + '%',
maxWidth: zoomRatio * 100 + '%',
marginTop: Math.round(shiftY * 2) + 'px',
marginLeft: Math.round(shiftX * 2) + 'px',
height: zoomHeight + 'px',
width: zoomWidth + 'px',
}"
@error.capture.prevent.stop.once="onFail"
@load="updateImgSize"
Expand Down Expand Up @@ -175,13 +175,13 @@ export default {
// scrolling position relative to the image
const scrollX = event.clientX - this.$el.x - (this.width * this.zoomRatio / 2)
const scrollY = event.clientY - this.$el.y - (this.height * this.zoomRatio / 2)
const scrollPercX = Math.round(scrollX / (this.width * this.zoomRatio) * 100) / 100
const scrollPercY = Math.round(scrollY / (this.height * this.zoomRatio) * 100) / 100
const scrollPercX = scrollX / (this.width * this.zoomRatio)
const scrollPercY = scrollY / (this.height * this.zoomRatio)
const isZoomIn = event.deltaY < 0
const newZoomRatio = isZoomIn
? Math.min(this.zoomRatio + 0.1, 5) // prevent too big zoom
: Math.max(this.zoomRatio - 0.1, 1) // prevent too small zoom
? Math.min(this.zoomRatio * 1.1, 5) // prevent too big zoom
: Math.max(this.zoomRatio / 1.1, 1) // prevent too small zoom
// do not continue, img is back to its original state
if (newZoomRatio === 1) {
Expand All @@ -195,8 +195,8 @@ export default {
// compensate for existing margins
this.disableSwipe()
this.shiftX = this.shiftX + Math.round(-scrollPercX * growX)
this.shiftY = this.shiftY + Math.round(-scrollPercY * growY)
this.shiftX = this.shiftX - scrollPercX * growX
this.shiftY = this.shiftY - scrollPercY * growY
this.zoomRatio = newZoomRatio
},
Expand Down Expand Up @@ -278,11 +278,8 @@ img {
justify-self: center;
// black while loading
background-color: #000;
// animate zooming/resize
transition: height 100ms ease,
width 100ms ease,
margin-top 100ms ease,
margin-left 100ms ease;
// disable animations during zooming/resize
transition: none !important;
// show checkered bg on hover if not currently zooming (but ok if zoomed)
&:hover {
background-image: linear-gradient(45deg, #{$checkered-color} 25%, transparent 25%),
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/Mime.js
Expand Up @@ -169,7 +169,7 @@ export default {
if (modalWrapper && this.naturalHeight > 0 && this.naturalWidth > 0) {
const modalContainer = modalWrapper.querySelector('.modal-container')

const parentHeight = modalContainer.clientHeight - 50 // header height
const parentHeight = modalContainer.clientHeight
const parentWidth = modalContainer.clientWidth

const heightRatio = parentHeight / this.naturalHeight
Expand Down

0 comments on commit 2f3384f

Please sign in to comment.