pawelgrzybek / siema

Siema - Lightweight and simple carousel in pure JavaScript
https://pawelgrzybek.github.io/siema/
Other
3.49k stars 408 forks source link

Multi siema Not work #240

Closed salamj closed 5 years ago

salamj commented 5 years ago

Hello

When make multi DIVs with the same class, only the first div works, And when (bad Idea) try to make for loop and use :

new Siema({
  selector: elm[i].
  ...
}

For each node , Also not work.

Thanks.

pawelgrzybek commented 5 years ago

There is an example on CodePen with multiple Siema instances. Please look for a solution first, open an issue then.

ademidun commented 2 years ago

For anyone wondering how to solve this, what worked for me is creating a unique class for each Siema Instance.

Here is some pseudocode:

//js
const carouselId1 = nanoid() // or (Math.random() + 1).toString(36).substring(7);
const carouselId2 = nanoid() // or (Math.random() + 1).toString(36).substring(7);

new Siema({
  selector: `.${carouselId1}`.
  ...
}
new Siema({
  selector: `.${carouselId2}`.
  ...
}
// html
<div>
<div className={carouselId1}>

</div>

<div className={carouselId2}>

</div>
</div>