Methods & properties
Constructor
ts
new InsigneSlider(target: HTMLElement | string, options?: Options): InsigneSlider| Parameter | Type | Description |
|---|---|---|
target | HTMLElement | string | The element (or a selector) whose children become slides. Must be able to host a shadow root. |
options | Options | Any options. Merged over markup options (data-*, JSON). |
If the element already has a slider, the existing instance is returned and the options are applied to it. Throws if the element is not found or cannot host a slider.
Static members
| Member | Signature | Description |
|---|---|---|
InsigneSlider.get | (target: Element | string | null) => InsigneSlider | undefined | The instance of an element. |
InsigneSlider.create | (target, spec: SliderSpec) => InsigneSlider | Renders slides from data and starts a slider. See JSON. |
InsigneSlider.init | (root?: ParentNode) => InsigneSlider[] | Starts every [data-insigne] under root (default document). |
InsigneSlider.autoInit | () => void | init() when the DOM is ready, and for elements added later. |
InsigneSlider.define | (sliderTag?, slideTag?) => void | Registers <insigne-slider> / <insigne-slide> (idempotent). |
InsigneSlider.effects | readonly string[] | All effect names. |
InsigneSlider.options | readonly OptMeta[] | Option metadata (name, type, default, values, range). |
InsigneSlider.defaults | Record<string, unknown> | Default values. |
InsigneSlider.version | string | Library version. |
Instance methods
All methods return the instance, so they can be chained, unless noted.
| Method | Signature | Description |
|---|---|---|
next | () => this | Next slide (respects loop). |
prev | () => this | Previous slide. |
goTo | (index: number, opts?: { instant?: boolean }) => this | Go to a slide (0-based). With a loop, takes the shortest way. |
play | () => this | Start autoplay (enables it if it was off). |
pause | () => this | Stop autoplay until play(). |
update | (options: Options) => this | Change options at runtime. The current slide is kept. |
refresh | () => this | Re-read slides from the DOM. Automatic when children change. |
addSlide | (content: Node | string, index?: number) => this | Insert a slide (element or HTML string). Default: at the end. |
removeSlide | (index: number) => this | Remove a slide. |
on | (event, handler) => () => void | Subscribe; returns an unsubscribe function. See events. |
once | (event, handler) => () => void | Subscribe for one call. |
off | (event, handler) => void | Unsubscribe. |
destroy | () => void | Stop everything, restore your markup and inline styles, release WebGL. |
Properties (read-only)
| Property | Type | Description |
|---|---|---|
el | HTMLElement | The slider element. |
index | number | Current slide (0-based, always the real index). |
count | number | Number of slides. |
slides | HTMLElement[] | The slide elements (a copy of the list). |
options | Readonly<Record<string, any>> | Resolved options (defaults + markup + constructor + updates). |
isPlaying | boolean | Autoplay is on and not stopped by the user (it may still be paused by hover or visibility). |
isMoving | boolean | A transition is running. |
Element API
<insigne-slider> forwards the common members, so you rarely need the instance:
| Member | Description |
|---|---|
el.slider | The InsigneSlider instance (after the element is ready). |
el.options | Get the resolved options; set an object to update. |
el.next(), el.prev(), el.goTo(i), el.play(), el.pause() | As above. |
el.index, el.count | As above. |
el.on(event, fn) | As above (after ready). Or listen to insigne:<event> DOM events. |