Exploring the capabilities of ngx-img-zoom with Angular using an HTML range slider

Implementing Angular ngx-img-zoom with simultaneous pinch-zoom and scroll zoom

https://i.sstatic.net/mT8WQ.gif

Answer №1

Below is the solution provided in HTML Page:

            <div
            [ngStyle]="{'transform': 'scale(' + scaleRange +  ')','transform-origin': xValue + 'px ' + yValue + 'px'}">
            <div>
                <lib-ngx-image-zoom (zoomScroll)="scroll($event)" (zoomPosition)="mouseMove($event)"
                    zoomMode="toggle-click" [thumbImage]='imageUrl' [fullImage]=imageUrl maxZoomRatio="10"
                    [scrollStepSize]=".1" magnification="1" enableScrollZoom="true" altText="img-not-found">
                </lib-ngx-image-zoom>
            </div>
        </div>
<input type="range" min="1" max="10" step=".1" value={{scaleRange}} class="form-range"
            style="width: 200px; height: 50px;" #ref (change)="valueChanged(ref.value)">

The code snippet above demonstrates how to implement an image with zoom control using a range input.

For the corresponding TypeScript file (.ts), refer to the code below:

  imageUrl: string;
  scaleRange: number;
  xValue: number;
  yValue: number;

valueChanged(value: number) {
    if (value === 1) {
      this.scaleRange = 1;
    } else {
      this.scaleRange = value;
    }
}

 scroll(magnification: number) {
    this.scaleRange = magnification;
}
mouseMove(event) {
    this.xValue = event.x;
    this.yValue = event.y;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Newest Angular package.json

Each time I attempt to update my Angular components to the latest version, I encounter the same error. It seems like a never-ending cycle... npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/ ...

Utilizing shared components across a Next.js application within a monorepo

Utilizing a monorepo to share types, DTOs, and other isomorphic app components from backend services (Nest.js) within the same mono repo has presented some challenges for me. In my setup, both the next.js app and nest.js app (which itself is a nest.js mono ...

Utilizing the power of the Google Calendar API with a service account in a Node.js environment

I have a vision to create an application with a specific feature set: Whenever there is a change in the user's Google calendar (an event is added, deleted, or edited), I want to receive updates with full event details. To achieve this, I understand ...

"Exploring ASP.NET 5 MVC6 Web API: Understanding how to handle Post requests with

Posting a JSON object in the body and binding it with [FromBody] or posting a header and binding it with [FromHeader(Name=...)] individually works fine. However, combining both methods does not seem to work. Is there a workaround or alternative way to bind ...

Accessing environment-based constants in TypeScript beyond the scope of Cypress.env()Is there a way to gain access to environment-specific constants

Imagine I have an API test and the URL and Credentials are different between production and development environments: before("Authenticate with auth token", async () => { await spec().post(`${baseUrl}/auth`) .withBody( { ...

Encountered an issue with `ng serve` following the execution of `ng update @angular/cli @angular/core` resulting in the inability to serve the

I encountered some issues in my Angular project when trying to build a docker image. To resolve the error, I utilized ng update @angular/cli @angular/core successfully, allowing me to now create a docker container for my project. However, I am facing a new ...

What is the timing for the execution of top-level non-export code in TypeScript?

I am currently puzzled about the execution of code in files. Let's say we have a file1.ts with the following content: export interface myInterface {} export function myFunction() {} export const myConst: {} // ... and more exports // top-level non- ...

Can I access the component attributes in Vuetify using Typescript?

For example, within a v-data-table component, the headers object contains a specific structure in the API: https://i.stack.imgur.com/4m8WA.png Is there a way to access this headers type in Typescript for reusability? Or do I have to define my own interfac ...

Protecting scripts using bypassSecurityTrustStyle in Angular

Is there a way to remove all script tags from a string while preserving the style? Consider this code snippet where we sanitize the style of a string: getSanitized(s: string) { const safeStyle: any = this.sanitizer.bypassSecurityTrustStyle(s); re ...

The collapsible tree nodes overlap one another in the D3.js visualization

I'm currently working on integrating a d3 code into Power BI for creating a collapsible tree structure. Each node in the tree is represented by a rectangular box, but I've run into an issue where nodes overlap when their size is large. Below is t ...

Why is it necessary for the required type of a function parameter to be able to be assigned to

From Optional to Required Type const testFunc = (func: (param: number) => void): void => { func(3); }; testFunc((a?: number) => { console.log(a); }); From Required to Optional Type const testFunc = (func?: (param: number) => void): void = ...

Using TypeScript for abstract methods and polymorphism

What do I need to fix in order for this code to function properly? abstract class Animal { // No constructor ... public abstract me():Animal; } class Cat extends Animal { constructor() { super(); } // Why does this no ...

Create a line break in the React Mui DataGrid to ensure that when the text inside a row reaches its maximum

I'm facing an issue with a table created using MUI DataGrid. When user input is too long, the text gets truncated with "..." at the end. My goal is to have the text break into multiple lines within the column, similar to this example: https://i.sstati ...

What is the method for transmitting a concealed attribute "dragable" to my component?

Currently, I have successfully integrated a here map into my project, but I am now tackling the challenge of adding draggable markers to this map. To achieve this, I am utilizing a custom package/module developed by my company. This package is designed to ...

Displaying error messages for duplicate inputs in template-driven forms

My current challenge involves implementing required validation for both a text field and a radio button group within a form. The validation works flawlessly for the text field, as shown below: <div class="formControl" [class.error]="carName.touched &am ...

The Angular2 component link imported in the core.module is not functioning properly

Adhering to the guidelines provided in the Angular style guide found at https://angular.io/styleguide#!#04-11, I have created a simple navigation setup. My app.component contains links like <a routerLink="hello">hello</a>, which work perfectly ...

What is the reason behind localStorage.getItem consistently returning a string value?

Something strange is happening. In the lib.dom.d.ts file, the type for localstorage.getItem shows as 'string | null', but in my app it always returns a string. Why is this discrepancy occurring? ...

I am seeking a way to access the child infoWindow within a Google Maps marker in Angular 5

I am working on an Angular 5 application that utilizes the Angular Google Maps(AGM) library available at . I have implemented functionality where clicking on an item in a list within one component triggers the display of a child infoWindow associated with ...

When an attribute is used as a selector for a component in Angular, it can often trigger errors in

Looking to develop a component with an attribute as a selector, here's what I have: @Component({ selector: '[my-attribute-selector]', template: `` }) export class MyComponent { // Some cool stuff } Running into a tslint error t ...

The correct way to incorporate a global property into a component template (using Vue 3, Vite, TypeScript, and the Composition API)

The component's property is not functioning properly https://i.sstatic.net/qaUG9.png src/main.ts import { createApp } from 'vue' import languagePlugin from '@/plugins/languagePlugin' import App from './App.vue' const a ...