Components · Carousel

组件

Carousel 轮播

轮播幻灯;data-pvs-carousel 挂载 JS,支持自动播放与指示点。

根节点加 data-pvs-carouseldata-pvs-carousel-autoplay="5000" 毫秒自动轮播(悬停/聚焦暂停)。

<div class="pvs-carousel pvs-carousel--ratio-16x9" data-pvs-carousel data-pvs-carousel-autoplay="6000" style="max-width:32rem">
  <div class="pvs-carousel__viewport">
    <div class="pvs-carousel__track">
      <div class="pvs-carousel__slide is-active">
        <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='360'%3E%3Crect fill='%232563eb' width='100%25' height='100%25'/%3E%3Ctext x='50%25' y='50%25' fill='white' font-size='32' text-anchor='middle' dominant-baseline='middle'%3E1%3C/text%3E%3C/svg%3E" alt="幻灯 1" />
      </div>
      <div class="pvs-carousel__slide">
        <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='360'%3E%3Crect fill='%23059669' width='100%25' height='100%25'/%3E%3Ctext x='50%25' y='50%25' fill='white' font-size='32' text-anchor='middle' dominant-baseline='middle'%3E2%3C/text%3E%3C/svg%3E" alt="幻灯 2" />
      </div>
      <div class="pvs-carousel__slide">
        <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='360'%3E%3Crect fill='%23d97706' width='100%25' height='100%25'/%3E%3Ctext x='50%25' y='50%25' fill='white' font-size='32' text-anchor='middle' dominant-baseline='middle'%3E3%3C/text%3E%3C/svg%3E" alt="幻灯 3" />
      </div>
    </div>
  </div>
  <button type="button" class="pvs-carousel__prev" aria-label="上一张">‹</button>
  <button type="button" class="pvs-carousel__next" aria-label="下一张">›</button>
  <div class="pvs-carousel__indicators" role="tablist" aria-label="幻灯指示">
    <button type="button" class="pvs-carousel__indicator is-active" aria-label="第 1 张">
    </button>
    <button type="button" class="pvs-carousel__indicator" aria-label="第 2 张">
    </button>
    <button type="button" class="pvs-carousel__indicator" aria-label="第 3 张">
    </button>
  </div>
</div>

去掉 data-pvs-carousel-autoplay 则仅箭头/指示器切换,无自动轮播。

<div class="pvs-carousel pvs-carousel--ratio-16x9" data-pvs-carousel style="max-width:24rem">
  <div class="pvs-carousel__viewport">
    <div class="pvs-carousel__track">
      <div class="pvs-carousel__slide is-active">
        <div class="pvs-carousel__caption">手动轮播 · 无 autoplay</div>
      </div>
      <div class="pvs-carousel__slide">
        <div class="pvs-carousel__caption">第二屏</div>
      </div>
    </div>
  </div>
  <button type="button" class="pvs-carousel__prev" aria-label="上一张">‹</button>
  <button type="button" class="pvs-carousel__next" aria-label="下一张">›</button>
</div>

div.pvs-carousel__viewport__track__slide;可选 prev/next 与 indicators

类名说明
pvs-carousel根(需 data-pvs-carousel)
pvs-carousel__track / __slide轨道与单页
pvs-carousel__prev / __next前后切换
pvs-carousel__indicator底部圆点
pvs-carousel--ratio-16x9固定 16:9 画幅
data-pvs-carousel-autoplay自动播放间隔(毫秒)