After you import Zoomist into your project, you can initialize it by using Zoomist function.
Zoomist can receive two parameters (zoomistElement & zoomistOptions), and returns initialized Zoomist instance.
For example:
const zoomist = new Zoomist('.zoomist-container', { maxScale: 4})After you initialize Zoomist, you can access Zoomist methods and properties from the instance. And you can also get the instance from your zoomistElement’s zoomist property:
For example:
const zoomist = new Zoomist('.zoomist-container')
zoomist.zoom(0.1)document.querySelector('.zoomist-container').zoomist.zoom(0.1)There are two parameters for class Zoomist:
| Parameter | Type | Description |
|---|---|---|
zoomistElement | HTMLElement | string | First parameter, Required. HTMLElement or string (CSS Selector) of zoomist container HTML element. |
zoomistOptions | object | Second parameter, Optional. A |
The second parameter zoomistOptions is optional, so you can initialize Zoomist simply like:
new Zoomist('.zoomist-container')// orconst zoomistElement = document.querySelector('.zoomist-container')new Zoomist(zoomistElement)And Zoomist will set the options to default.
All available options and initial value:
| Name | Type | Default | Description |
|---|---|---|---|
bounds | boolean | true | Set |
draggable | boolean | true | Set |
wheelable | boolean | true | Set |
pinchable | boolean | true | Set |
minScale | number | 1 | Set minimum scale size. Should be smaller than
|
maxScale | number | 10 | Set maximum scale size. Should be bigger than |
initScale | number | null | null | Set initial scale size. Should be bigger than |
zoomRatio | number | 0.1 | Set the zoom ratio. |
disableDraggingClass | string | 'zoomist-not-draggable' | Elements matched this class will not be dragged. |
disableWheelingClass | string | 'zoomist-not-wheelable' | Elements matched this class will not be zoomed by mouse wheel. |
dragReleaseOnBounds | boolean | false | If set to
|
wheelReleaseOnMinMax | boolean | false | If set to
|
smooth | boolean | SmoothOptions | Set to
| |
slider | boolean | SliderOptions | The slider tool of Zoomist. | |
zoomer | boolean | ZoomerOptions | The zoom tools of Zoomist. |
For example:
new Zoomist('.zoomist-container', { maxScale: 4, initScale: 2, slider: true})Zoomist provide a simple slider tool for you. You can set option slider to true and Zoomist will create a horizontal slider in your zoomistElement. Or you can use these following options and to customize slider.
All available slider options:
| Name | Type | Default | Description |
|---|---|---|---|
el | HTMLElement | string | null | null | Receives a |
direction | 'horizontal' | 'vertical' | 'horizontal' | Set your slider horizontal or vertical. |
For example:
<!-- custom slider --><div class="custom-zoomist-slider"></div><!-- zoomist --><div class="zoomist-container"> <div class="zoomist-wrapper"> <div class="zoomist-image"> <!-- your content --> </div> </div></div>new Zoomist('.zoomist-container', { slider: { el: '.custom-zoomist-slider', direction: 'vertical' }})To customize slider’s styles, checkout these CSS variables.
Zoomist also provide some zoom tools for you, like: zoom-in button, zoom-out button, reset button. You can set option zoomer to true and Zoomist will create those buttons in your zoomistElement. Or you can use these following options and to customize zoomer.
All available zoomer options:
| Name | Type | Default | Description |
|---|---|---|---|
el | HTMLElement | string | null | null | Define the container of all zoomer buttons. |
inEl | HTMLElement | string | null | null | Define the zoom-in button. If you set it to keyword |
outEl | HTMLElement | string | null | null | Define the zoom-out button. If you set it to keyword |
resetEl | HTMLElement | string | null | null | Define the reset button. If you set it to keyword |
disabledClass | string | false | null | 'zoomist-zoomer-disabled' | Set the disable class. It will be added on |
For example:
<!-- custom zoomer --><div class="custom-zoomist-zoomer"> <button class="custom-zoomer-in">+</button> <button class="custom-zoomer-out">-</button></div><!-- zoomist --><div class="zoomist-container"> <div class="zoomist-wrapper"> <div class="zoomist-image"> <!-- your content --> </div> </div></div>new Zoomist('.zoomist-container', { zoomer: { inEl: '.custom-zoomer-in', outEl: '.custom-zoomer-out' }})To customize zoomer’s styles, checkout these CSS variables.