spz-carousel

When to Use

  • Commonly used for the carousel of a group of images.
  • When you want to automatically cycle through multiple images, you can use a carousel for display.

Code Demonstration

Basic Usage

The simplest usage.

<spz-carousel layout="responsive" width="640" height="427" controls>
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Custom Button Icons

  • Use child elements with the pre attribute to replace the icon for the previous button.
  • Use child elements with the next attribute to replace the icon for the next button.
<spz-carousel layout="responsive" width="640" height="427" controls loop>
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>

  <svg pre xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path d="M13.1714 12.0007L8.22168 7.05093L9.63589 5.63672L15.9999 12.0007L9.63589 18.3646L8.22168 16.9504L13.1714 12.0007Z" fill="#fff"></path></svg>
  <svg next xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path d="M13.1714 12.0007L8.22168 7.05093L9.63589 5.63672L15.9999 12.0007L9.63589 18.3646L8.22168 16.9504L13.1714 12.0007Z" fill="#fff"></path></svg>
</spz-carousel>

Automatic Switching

Switch to the next slide automatically at set intervals, supporting loop playback by default (even without configuring the loop attribute).

<spz-carousel layout="responsive" width="640" height="427" autoplay delay="2000">
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Fade Effect

The transition effect is a fade.

<spz-carousel layout="responsive" width="640" height="427" controls loop effect="fade" animate-time="1000">
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Auto-Adjustable Height

Automatically adjusts to the height of different slides when switching.

<spz-carousel layout="container" controls loop effect="fade" animate-time="800" auto-height>
  <spz-img src="https://img.staticdj.com/969d7faa33893c0cd941900ac3abc4ba.webp" alt="White rose" layout="responsive" width="640" height="960" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/546292026322dcd1060dc9fdfc42c9ca.jpg" alt="Flower" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Display Multiple Slides at Once

1.2 slides are visible at the same time.

<spz-carousel layout="responsive" width="640" height="427" loop visible-count="1.2">
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Full-Screen Enlargement Mode

Click on a slide to enter full-screen enlargement mode.

<spz-carousel layout="responsive" width="640" height="427" loop zoom>
  <spz-img src="https://img.staticdj.com/e858445e80fa04320cff7fd6473335d2.webp" alt="Pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/7b45d0021c8955d7a38334a4b6a92609.webp" alt="Full pink rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
  <spz-img src="https://img.staticdj.com/0c67bf474af38d7abefb6c5da5dd6770.webp" alt="Red rose" layout="responsive" width="640" height="427" object-fit="cover"></spz-img>
</spz-carousel>

Attributes

Attribute NameDescriptionTypeDefault ValueMandatory
initial-slideWhich slide to display by defaultnumber0No
advance-countNumber of slides that can be seen and switched at the same timenumber1No
visible-countNumber of currently visible slides; only one slide can be switched at a time, supports decimals, for example: 1.8number1No
zoomIf this attribute exists, click on the slide to enter full-screen enlargement mode--No
controlsIf this attribute exists, display left and right toggle buttons--No
loopIf this attribute exists, the carousel supports looping--No
autoplayIf this attribute exists, the slides begin automatic switching--No
delayAuto-switch delay, in millisecondsnumber5000No
animate-timeTransition animation time, in millisecondsnumber300No
effectTransition animation effect, options: fade | scrollerstringscrollerNo
directHorizontal or vertical direction, options: horizontal | verticalstringhorizontalNo
scroll-ratioThe distance to slide one slide's width multiplied by this value to trigger switching to the next slide, value range 0-1number0.01No
auto-heightIf this attribute exists, when the height of slides is inconsistent, the switch will have an animated effect--No
zoom-inWhen the slide enters full-screen enlargement mode, the root element automatically adds this attribute---

Slide Container Attributes

Attribute NameDescriptionType
selectThe index of the currently displayed slide, starting from 0number

Methods

goToSlide

Switch to a specific slide.

ParameterDescriptionTypeMandatory
pathThe src of the slidestringYes, unless there is an index parameter
indexThe index of the slide, starting from 0stringYes, unless there is a path parameter
animateWhether the switch includes an animation effectbooleanNo

updateDirect

Update the direct attribute of the carousel.

ParameterDescriptionTypeMandatory
directThe number of slides that can be switched at the same timenumberYes

updateCount

Update the advance-count attribute of the carousel.

ParameterDescriptionTypeMandatory
countThe horizontal or vertical direction, options: horizontal | verticalstringYes

goPrev

Switch to the previous slide, no parameters needed.

goNext

Switch to the next slide, no parameters needed.

calcPosition

Recalculate the position of the switching buttons. It is effective only when the controls attribute is configured, no parameters needed.

Events

Event Object Data

AttributeDescriptionType
totalThe total number of slidesnumber
indexThe index of the current slide, starting from 0number
isImageThe type of the slide, returns true if it's an imageboolean
tagNameThe tag name of the slide, for example: DIVstring
pathThe src attribute of the slidestring | null

mounted

This event is automatically triggered when the carousel is mounted.

mediaChange

This event is automatically triggered when the page is adjusted to match the size of media queries. Supported attributes: advance-count, visible-count.

slideEnd

This event is automatically triggered when the slide transition animation is complete.

slideChange

This event is automatically triggered when the slide transition animation is in progress.

zoomIn

This event is automatically triggered when the slide enters full-screen enlargement mode.

zoomOut

This event is automatically triggered when the slide exits full-screen enlargement mode.

AI Summary (LLM Ready)

  • Component ID: spz-carousel
  • One-line purpose: A carousel for cyclically showcasing a series of images, videos, etc., with support for automatic playback or manual switching by users.
  • Detected attribute rows: 15
  • Detected method subsections: 6
  • Detected event subsections: 7
  • Top attribute names: initial-slide, advance-count, visible-count, zoom, controls, loop
  • Top method names: goToSlide, updateDirect, updateCount, goPrev, goNext, calcPosition
  • Top event names: mounted, mediaChange, slideEnd, slideChange, zoomIn
  • Reading order: start from usage/examples, then verify attributes, methods, and events.
  • Related docs: /en/guide/actions-and-events/ , /en/guide/layouts/