Code Monkey home page Code Monkey logo

ionic2-zoom-area-example's Introduction

npm npm npm

A zoom area for Ionic 2

A zoom area component with pinch support to zoom any element in page

To see this in action, checkout the example project here.

IMPORTANT: This module requires Angular Animations and should be included in the app module.


Screenshot






Quick Example

<zoom-area>
  <div>
      zoom it
  </div>
  or
  <img src="zoom-it.jpg" alt="zoom it">
</zoom-area>




Installation

Add Angular Animations

npm i --save @angular/animations

Import BrowserAnimationsModule in your app's module(s)

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

And then

imports: [
  ...
  BrowserAnimationsModule,
  ...
]

Install the module via NPM

npm i --save ionic2-zoom-area

Import it in your app's module(s)

Import ZoomAreaModule.forRoot() in your app's main module

import { ZoomAreaModule } from 'ionic2-zoom-area';

@NgModule({
    ...
    imports: [
      ...
      ZoomAreaModule.forRoot()
    ],
    ...
})
export class AppModule {}

If your app uses lazy loading, you need to import ZoomAreaModule in your shared module or child modules:

import { ZoomAreaModule } from 'ionic2-zoom-area';

@NgModule({
    ...
    imports: [
      ...
      ZoomAreaModule
    ],
    ...
})
export class SharedModule {}




Usage

zoom-area Component

Inputs

scale

(optional) (two-way) The scale of your initial zoom. Defaults to 1.

controls

(optional) (two-way) It allow you to hide or show zoom controls. Defaults to true.

Outputs

afterZoomIn

Listen to this event to be notified when the user interact with zoom in.

afterZoomOut

Listen to this event to be notified when the user interact with zoom out.



ZoomAreaProvider Provider

notifyScroll

notifyScroll(): void

It broadcast an event when user scroll content inside zoom area.

onScroll$

onScroll$: Observable

It allows you to listen for a scroll event inside your zoom area. You can use it to collapse you header for example.

this.zoomAreaProvider.onScroll$.subscribe(state => {
  if (state === this.zoomAreaProvider.SCROLL_STATE.COLLAPSED) {
    console.log('Hide header');
  }

  if (state === this.zoomAreaProvider.SCROLL_STATE.EXPANDED) {
    console.log('Show header');
  }
});

scrollState$

scrollState$: Observable

It allows you to listen for a change in scroll state.

this.zoomAreaProvider.scrollState$.subscribe(state => {
  console.log('Do whatever you want when scrollState change');
});

setCenter (x: number, y: number)

setCenter: Function

It allows you to change the position of the zoom manually if zoom scale is greather than 1.

this.zoomAreaProvider.setCenter(x, y);
this.zoomAreaProvider.setCenter(20, 50);

Examples

Basic example

Example with methods

<zoom-area [(scale)]="scale" (afterZoomIn)="afterZoomIn($event)" (afterZoomOut)="afterZoomOut($event)" [(controls)]="showControls">
    <div>Zoom It</div>
    or
    <img src="assets/image-to-zoom.jpg" alt="Zoom It">
</zoom-area>



Roadmap

  • ✅(1.0.10) - Add support to move center of zoom



Contribution

  • Having an issue? or looking for support? Open an issue and we will get you the help you need.
  • Got a new feature or a bug fix? Fork the repo, make your changes, and submit a pull request.

Support this project

If you find this project useful, please star the repo to let people know that it's reliable. Also, share it with friends and colleagues that might find this useful as well. Thank you 😄

ionic2-zoom-area-example's People

Contributors

leonardosalles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ionic2-zoom-area-example's Issues

ISSUES ON INSTALLATION

typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
',' expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Type parameter declaration expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Expression expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
')' expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
';' expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Declaration or statement expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
'(' expected.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...HSC/mobile5/node_modules/@angular/platform-browser/animations/src/providers.d.ts, line: 8
Module '"D:/EDUMASR/mobile apps/CLUBS/HSC/mobile5/node_modules/@angular/animations/browser"' has no exported
member 'ɵDomAnimationEngine'.

   L8:  export declare function instantiateSupportedAnimationDriver(): NoopAnimationDriver;
   L9:  export declare function instantiateDefaultStyleNormalizer(): WebAnimationsStyleNormalizer;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Object is possibly 'undefined'.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Cannot find name 'key'.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
Cannot find name 'string'.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

[13:30:15] typescript: ...zoom-area/node_modules/@angular/platform-browser/src/browser/transfer_state.d.ts, line: 34
'StateKey' only refers to a type, but is being used as a value here.

  L34:  export declare function makeStateKey<T = void>(key: string): StateKey<T>;

Error: Failed to transpile program
at BuildError.Error (native)
at new BuildError (D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\util\errors.js:16:28)
at D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\transpile.js:137:20
at transpileWorker (D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\transpile.js:103:12)
at Object.transpile (D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\transpile.js:61:12)
at buildProject (D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\build.js:97:78)
at D:\EDUMASR\mobile apps\CLUBS\HSC\mobile5\node_modules@ionic\app-scripts\dist\build.js:47:16

Using it inside an ion-slider

Hi,

I'm trying to use this component inside an ion-slide in ionic 3.9.2. However the moment i pinch the image disappears.

Also the slides within a modal so maybe it has some z-index issue ?

Could you look into this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.