# Zoom and Pan

zooming and panning is one of the popular interactions, helps focus on the region of interest. I2Djs provides an intuitive way to define the zoom behavior on SVG, Canvas, and webGL layers. I2Djs support multiple interactions as specified below:

**Panning: Click and drag, Touch.**

**Zoom: On the spin wheel, Pinch(2 pointer event),  vertical scroll**.

{% embed url="<https://codepen.io/nswamy14/pen/XWXWeKb>" %}

### API

```
let zoomInstance = i2d.behaviour.zoom()
```

**zoomStart:** Triggered on zoom start.

```
zoomInstance.zoomStart(function(event){

})
```

**zoom:** Triggered continuously on zoom. It will be triggered after **zoomStart** till **zoomEnd.**

```
zoomInstance.zoom(function(event){

})
```

**zoomEnd:** Triggered once on zoom ends.

```
zoomInstance.zoomEnd(function(event){

})
```

### Zoom configuration:

zoomInstance.scaleExtent(\[minScale, MaxScale]);

zoomInstance.panExtent(\[`topLeft`\[x, y], `bottomRight`\[x, y]]);

zoomInstance.zoomTarget(`point[x, y]`);

zoomInstance.zoomFactor(value);

zoomInstance.duration();

### Methods inherited by context node:

node.zoomTo(`zoomScale`, `point`);

node.zoomBy(`zoomScale`, `point`);

node.panTo(`point`)

## Usage:

```
let zoomInstance = i2d.behaviour.zoom()
zoomInstance.zoomStart(function (event) {
    node.setAttr('transform', event.transform);
});
zoomInstance.zoom(function (event) {
    node.setAttr('transform', event.transform);
});
zoomInstance.zoomEnd(function (event) {
    node.setAttr('transform', event.transform);
});

node.on('zoom', zoomInstance);

//Inherited methods:
node.zoomTo(zoomScale, point);
node.zoomBy(zoomScale, point);
node.panTo(point);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nswamy14.gitbook.io/i2djs/api-reference/behaviour/zoom-and-pan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
