After initialize Zoomist, you can access methods and properties in initialized instance.
For example:
const zoomist = new Zoomist('.zoomist-container')
// methodzoomist.zoom(0.1)// propertyconsole.log(zoomist.transform)
All available methods (take zoomist
variable in example above):
Method | Args Type | Description |
---|---|---|
zoomist.zoom(scale) | scale: number | Zoom
|
zoomist.zoomTo(scale) | scale: number | Zoom |
zoomist.move(translate) | translate: {x: number, y: number} | Translate |
zoomist.moveTo(translate) | translate: {x: number, y: number} | Translate
|
zoomist.slideTo(value) | value: number | Set the slider to a specific value between 0 and 100. |
zoomist.reset() | Set | |
zoomist.destroy(cleanStyle) | cleanStyle: boolean | Destroy Zoomist and remove all event listeners. |
zoomist.destroySlider() | Destroy Zoomist slider. | |
zoomist.destroyZoomer() | Destroy Zoomist zoomer. | |
zoomist.destroyModules() | Destroy both slider and zoomer. | |
zoomist.update(options) | options: ZoomistOptions | Update Zoomist. |
zoomist.getContainerData() | Get | |
zoomist.getImageData() | Get | |
zoomist.getSliderValue() | Get slider current value. | |
zoomist.isOnBoundX() | Check | |
zoomist.isOnBoundY() | Check | |
zoomist.isOnBoundTop() | Check | |
zoomist.isOnBoundBottom() | Check | |
zoomist.isOnBoundLeft() | Check | |
zoomist.isOnBoundRight() | Check | |
zoomist.isOnMinScale() | Check | |
zoomist.isOnMaxScale() | Check | |
zoomist.on(event, handler) | event: string, handler: function | Add event handler. (Checkout all events) |
With these useful methods, you can do a lot of extra things.
For example, making a centered-button:
<!-- centered-button --><button class="centered-button"></button><!-- zoomist --><div class="zoomist-container"> <div class="zoomist-wrapper"> <div class="zoomist-image"> <!-- your content --> </div> </div></div>
const zoomist = new Zoomist('.zoomist-container')
document.querySelector('.centered-button').addEventListener('click', () => { zoomist.moveTo({ x: 0, y: 0 })})
Porperty | Type | Description |
---|---|---|
zoomist.element | HTMLElement |
|
zoomist.wrapper | HTMLElement |
|
zoomist.image | HTMLElement |
|
zoomist.options | object | Object with passed |
zoomist.mounted | boolean |
|
zoomist.states | object | The states of |
zoomist.transform | object | Transform data of |
zoomist.data | object | Data when Zoomist working. |
You can get some useful data from these properties.
For example, getting your current scale:
const zoomist = new Zoomist('.zoomist-container')
document.querySelector('.get-scale-button').addEventListener('click', () => { const { scale } = zoomist.transform console.log(scale)})