# Paging

## Commands

### `goToPage`

Navigates to the specified page in the flipbook.

```javascript
instance.paging.goToPage(4);
```

### `goToNextPage`

Navigates to the next page in the flipbook. If the flipbook has a spread-based layout, it will navigate to the next spread.

```javascript
instance.paging.goToNextPage();
```

### `goToPrevPage`

Navigates to the previous page in the flipbook. If the flipbook has a spread-based layout, it will navigate to the previous spread.

```javascript
instance.paging.goToPrevPage();
```

### `getState`

Gets the current paging state.

```javascript
// You can either await the result of the command
const result = await instance.paging.getState();

// OR pass a callback
instance.paging.getState((result) => {
    // YOUR CODE HERE
});
```

The command will return an object with the following properties:

| Property        | Type                | Description                               |
| --------------- | ------------------- | ----------------------------------------- |
| `currentSpread` | `number[]`          | The current visible pages of the flipbook |
| `spreads`       | Array of `number[]` | All spreads of the flipbook               |
| `totalPages`    | `number`            | Total amount of pages in the flipbook     |

## Events

### `onChange`

This subscription will trigger when the spread of a flipbook changes.

```javascript
instance.paging.onChange((result) => {
    // YOUR CODE HERE
});
```

The callback contains a value/result with the following properties:

| Property        | Type                | Description                               |
| --------------- | ------------------- | ----------------------------------------- |
| `currentSpread` | `number[]`          | The current visible pages of the flipbook |
| `spreads`       | Array of `number[]` | All spreads of the flipbook               |
| `totalPages`    | `number`            | Total amount of pages in the flipbook     |


---

# 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://docs.ipaper.io/flipbook-javascript-api/commands-and-events/paging.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.
