# Chaining

Sometimes we may need to chain multiple animations in a controlled way to achieve the desired effect. I2Djs provides a couple of chaining APIs, **sequenceChain** and **parallelChain,** to chain one or more animations sequentially / parallel respectively.  Chaining APIs provides great control in implementing complex animations easily.&#x20;

It even allows nested chaining - one chain within another.

Chaining methods are available as a part of I2D Object space.

Or It can be imported as below.

```
import {chain} from 'i2djs';
```

## APIs

### I2d.sequenceChain()

```
let ChainInstance = i2d.chain.sequenceChain()
```

sequenceChain is used to perform one or more animations in sequential order.

### I2d.parallelChain()

```
let ChainInstance = i2d.chain.parallelChain()
```

parallelChain is used to perform one or more animations simultaneously.

## ChainInstance APIs

**#.add(); -** Add anime executables to the chain instance. Anime executables can be obtained using - **animateExe** method.&#x20;

Example:&#x20;

```
chain.add(node.animateExe({
			duration: 1000,
			ease: 'easeInOutSin',
			attr: {
				x2: da.x,
				y2: da.y
			},
			end: function (d) {
				render(d);
			}
		}));
```

**#.duration(***Milliseconds***); -** Set chain duration in milliseconds. Entire chain will be completed in the specified duration. In the case of a sequential chain, the duration gets split among the animations. whereas in a parallel chain, all animations get the same duration.

**#.loop(***Number***); -** Number of times chain needs to be execute&#x64;**.**

**#.end(***exec***); -** On end of the chain execution, ***exec*** function will be called.

**#.direction(); -** Direction in which the chain execution should take place. **Default** - First child to last, **Reverse** - Last child to first.

**#.start(); -** A method to invoke the chain execution.&#x20;


---

# 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-v5/api-reference/chaining.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.
