Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Mouse wheel (zoom) on canvas img

React beginner here, i have a canvas where is img, i wanted to implement zooming when user takes mouse on the picture then user could zoom in and out using mouse wheel, i implemented it correctly because now zoom in and zoom out is possible but got one problem, img becomes smaller (but zooming works), if i remove 'TransformComponent' then img becomes bigger(as it should be this size) but user cannot zoom anymore.

English is not my mother language so could be mistakes .

import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";


renderPreview() {
    const camera = this.props.currentCamera;

    // render size (not display size) of the canvas
    const canvasRenderWidth = camera
      ? camera.width
      : this.state.config.previewStyle.width;
    const canvasRenderHeight = camera
      ? camera.height
      : this.state.config.previewStyle.height;
    // display size of the canvas
    let canvasStyle = {
      width: canvasRenderWidth >= canvasRenderHeight ? "100%" : "auto",
      height: canvasRenderHeight > canvasRenderWidth ? "100%" : "auto",
    };
    return (
      <div style={this.state.config.previewStyle}>
        <TransformWrapper
       
        >
          <TransformComponent>
            <canvas
              ref="CameraPreviewCanvas"
              width={canvasRenderWidth}
              height={canvasRenderHeight}
              onClick={this.onClickCanvas}
              onMouseMove={this.onMouseOverCanvas}
              style={canvasStyle}
            ></canvas>
          </TransformComponent>
        </TransformWrapper>

        <img
          ref="CameraPreviewImage"
          src={this.state.snapshot.snapshotUrl}
          style={{ display: "none" }}
        ></img>
      </div>
    );
  }

img:

enter image description here

i want img width to be 100% as it is without 'TransformComponent'

any idea how to fix this ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!