Parameters & Options

After you import Zoomist into your project, you can initialize it by using Zoomist function.

Zoomist instance

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)

Parameters

There are two parameters for class Zoomist:

ParameterTypeDescription
zoomistElementHTMLElement | stringFirst parameter, Required. HTMLElement or string (CSS Selector) of zoomist container HTML element.
zoomistOptionsobjectSecond parameter, Optional. A Object with Zoomist options.

The second parameter zoomistOptions is optional, so you can initialize Zoomist simply like:

new Zoomist('.zoomist-container')
// or
const zoomistElement = document.querySelector('.zoomist-container')
new Zoomist(zoomistElement)

And Zoomist will set the options to default.

Options

All available options and initial value:

NameTypeDefaultDescription
boundsbooleantrue

Set .zoomist-image can be scaled or dragged out of bounds.

draggablebooleantrue

Set .zoomist-image is draggable.

wheelablebooleantrue

Set .zoomist-image can be scaled when mouse wheeling.

pinchablebooleantrue

Set .zoomist-image is pinchable when pinching. (Only works on mobile device)

minScalenumber1

Set minimum scale size. Should be smaller than initScale.

if bounds set to true and minScale < 1, minScale will be set to 1 automatically.

maxScalenumber10

Set maximum scale size. Should be bigger than minScale.

initScalenumber | nullnull

Set initial scale size. Should be bigger than minScale and smaller than maxScale.
If set to null, it will take minScale as initScale.

zoomRationumber0.1

Set the zoom ratio.

disableDraggingClassstring'zoomist-not-draggable'

Elements matched this class will not be dragged.

disableWheelingClassstring'zoomist-not-wheelable'

Elements matched this class will not be zoomed by mouse wheel.

dragReleaseOnBoundsbooleanfalse

If set to true, enable to release touch events to allow for further page scrolling when .zoomist-image is on bounds.

Only works on devices have touch events and bounds set to true.

wheelReleaseOnMinMaxbooleanfalse

If set to true, enable to release wheel events to allow for further page scrolling when .zoomist-image is on mixScale or maxScale.

Only works on devices have wheel events.

sliderboolean | SliderOptions

The slider tool of Zoomist.
Set to true to enable slider quickly. (See more slider options)

zoomerboolean | ZoomerOptions

The zoom tools of Zoomist.
Set to true to enable zoomer quickly. (See more zoomer options)

For example:

new Zoomist('.zoomist-container', {
maxScale: 4,
initScale: 2,
slider: true
})

Slider

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:

NameTypeDefaultDescription
elHTMLElement | string | nullnull

Receives a HTMLElement or a string (CSS Selector) and use it as the container of the slider.

direction'horizontal' | 'vertical''horizontal'

Set your slider horizontal or vertical.

For example:

index.html
<!-- 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>
main.js
new Zoomist('.zoomist-container', {
slider: {
el: '.custom-zoomist-slider',
direction: 'vertical'
}
})

To customize slider’s styles, checkout these CSS variables.

Zoomer

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:

NameTypeDefaultDescription
elHTMLElement | string | nullnull

Define the container of all zoomer buttons.

inElHTMLElement | string | nullnull

Define the zoom-in button.
If you set it to keyword .zoomist-zoomer-in, Zoomist will generate a zoom-in button for you.

outElHTMLElement | string | nullnull

Define the zoom-out button.
If you set it to keyword .zoomist-zoomer-out, Zoomist will generate a zoom-out button for you.

resetElHTMLElement | string | nullnull

Define the reset button.
If you set it to keyword .zoomist-zoomer-reset, Zoomist will generate a reset button for you.

disabledClassstring | false | null'zoomist-zoomer-disabled'

Set the disable class.
It will be added on inEl when scale reaches the maxScale, be added on outEl when scale reaches the minScale, and be added on resetEl when scale reaches the initScale.

For example:

index.html
<!-- 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>
main.js
new Zoomist('.zoomist-container', {
zoomer: {
inEl: '.custom-zoomer-in',
outEl: '.custom-zoomer-out'
}
})

To customize zoomer’s styles, checkout these CSS variables.