aboutsummaryrefslogtreecommitdiff
path: root/viewer
diff options
context:
space:
mode:
authorpacien2020-04-26 20:01:46 +0200
committerpacien2020-04-26 20:01:46 +0200
commitf8a1763c3bee0e236c86ba9f6b46aceb212dea10 (patch)
tree8570dc9cb75921aea1c6f52a97ed61263483d182 /viewer
parentb86d96f2ed5dd4f17b047e8aba22512400484bb3 (diff)
downloadldgallery-f8a1763c3bee0e236c86ba9f6b46aceb212dea10.tar.gz
viewer/LdPicture: initially fit image in viewport
Diffstat (limited to 'viewer')
-rw-r--r--viewer/src/services/ldzoom.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/viewer/src/services/ldzoom.ts b/viewer/src/services/ldzoom.ts
index f001805..61b5dc6 100644
--- a/viewer/src/services/ldzoom.ts
+++ b/viewer/src/services/ldzoom.ts
@@ -28,7 +28,7 @@ export default class LdZoom {
28 readonly imageElement: HTMLImageElement; 28 readonly imageElement: HTMLImageElement;
29 readonly maxScaleFactor: number; 29 readonly maxScaleFactor: number;
30 readonly zoomSpeed: number; 30 readonly zoomSpeed: number;
31 scaleFactor: number; 31 scaleFactor: number = 0.0;
32 32
33 constructor( 33 constructor(
34 containerElement: HTMLDivElement, imageElement: HTMLImageElement, 34 containerElement: HTMLDivElement, imageElement: HTMLImageElement,
@@ -38,9 +38,12 @@ export default class LdZoom {
38 this.imageElement = imageElement; 38 this.imageElement = imageElement;
39 this.maxScaleFactor = maxScaleFactor; 39 this.maxScaleFactor = maxScaleFactor;
40 this.zoomSpeed = zoomSpeed; 40 this.zoomSpeed = zoomSpeed;
41 this.scaleFactor = imageElement.clientWidth / imageElement.naturalWidth;
42 } 41 }
43 42
43 /**
44 * Register event listeners.
45 * The dimension of the image should be known before calling this method.
46 */
44 public install() { 47 public install() {
45 new ResizeObserver(() => { 48 new ResizeObserver(() => {
46 this.setImageScale(this.scaleFactor); 49 this.setImageScale(this.scaleFactor);
@@ -53,8 +56,6 @@ export default class LdZoom {
53 }); 56 });
54 57
55 // TODO: handle pinch-to-zoom. 58 // TODO: handle pinch-to-zoom.
56
57 this.recenterImageElement();
58 } 59 }
59 60
60 /** 61 /**