跳到主要内容

文档

滑块

创建一个响应式的轮播滑块。

滑块组件完全响应式,支持触摸和滑动导航,以及桌面上的鼠标拖动。当您点击“上一个”和“下一个”导航时,它甚至会加速以跟上您的步伐。所有动画都经过硬件加速,以获得更流畅的性能。

用法

要应用此组件,请将 uk-slider 属性添加到容器元素,并使用 .uk-slider-items 类创建幻灯片列表。将图像或任何其他内容添加到每个项目。

要定义滑块项目的宽度,请使用宽度组件。可以使用 .uk-child-width-* 类来定义所有滑块项目的宽度,也可以使用 .uk-width-* 类为每个列表项应用单独的宽度。如果没有设置特定的宽度,则每个项目的宽度取决于内容本身的尺寸。

<div uk-slider>
    <div class="uk-slider-items uk-child-width-1-3@s uk-child-width-1-4@">
        <div>
            <img src="" width="" height="" alt="">
        </div>
    </div>
</div>

1

2

3

4

5

6

7

8

9

10

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider>

    <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m">
        <div>
            <img src="images/slider1.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>1</h1></div>
        </div>
        <div>
            <img src="images/slider2.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>2</h1></div>
        </div>
        <div>
            <img src="images/slider3.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>3</h1></div>
        </div>
        <div>
            <img src="images/slider4.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>4</h1></div>
        </div>
        <div>
            <img src="images/slider5.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>5</h1></div>
        </div>
        <div>
            <img src="images/slider1.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>6</h1></div>
        </div>
        <div>
            <img src="images/slider2.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>7</h1></div>
        </div>
        <div>
            <img src="images/slider3.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>8</h1></div>
        </div>
        <div>
            <img src="images/slider4.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>9</h1></div>
        </div>
        <div>
            <img src="images/slider5.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>10</h1></div>
        </div>
    </div>

    <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
    <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>

</div>

注意 要在幻灯片中延迟加载图像,请使用 loading="lazy" 属性。滑块会自动从相邻幻灯片中的图像中删除该属性。


容器

.uk-slider-container 类负责裁剪滑块项目。默认情况下,uk-slider 属性将此类别应用于同一元素。或者,您可以手动将此类添加到滑块中的任何元素。这样,您可以控制哪个容器裁剪滑块项目。

<div uk-slider>

    <div class="uk-slider-container">
        <div class="uk-slider-items uk-child-width-1-4">
            <div>
                <img src="" width="" height="" alt="">
            </div>
        </div>
    </div>

</div>

由于滑块效果需要一个裁剪容器,内容项目的阴影也会被裁剪。要加宽容器以防止阴影被裁剪,请添加 .uk-slider-container-offset 类。


间隙

要将间隙应用于滑块项目,请使用网格组件并将 .uk-grid 类添加到滑块。然后,元素将根据网格间隙进行间隔。您可以使用 .uk-grid-small 等修饰符来更改间隙。

<div uk-slider>
    <div class="uk-slider-items uk-child-width-1-2@s uk-child-width-1-3@m uk-grid">
        <div>
            <img src="" width="" height="" alt="">
        </div>
    </div>
</div>

1

2

3

4

5

6

7

8

9

10

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider>

    <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@m uk-grid">
        <div>
            <div class="uk-panel">
                <img src="images/slider1.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>1</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider2.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>2</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider3.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>3</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider4.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>4</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider5.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>5</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider1.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>6</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider2.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>7</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider3.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>8</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider4.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>9</h1></div>
            </div>
        </div>
        <div>
            <div class="uk-panel">
                <img src="images/slider5.jpg" width="400" height="600" alt="">
                <div class="uk-position-center uk-panel"><h1>10</h1></div>
            </div>
        </div>
    </div>

    <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
    <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>

</div>

居中

默认情况下,滑块的项目始终与左对齐。要使列表项目居中,只需将 center: true 添加到属性。

<div uk-slider="center: true">…</div>

1

2

3

4

5

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider="center: true">

    <div class="uk-slider-items uk-grid">
        <div class="uk-width-3-4">
            <div class="uk-panel">
                <img src="images/photo.jpg" width="600" height="400" alt="">
                <div class="uk-position-center uk-panel"><h1>1</h1></div>
            </div>
        </div>
        <div class="uk-width-3-4">
            <div class="uk-panel">
                <img src="images/dark.jpg" width="600" height="400" alt="">
                <div class="uk-position-center uk-panel"><h1>2</h1></div>
            </div>
        </div>
        <div class="uk-width-3-4">
            <div class="uk-panel">
                <img src="images/light.jpg" width="600" height="400" alt="">
                <div class="uk-position-center uk-panel"><h1>3</h1></div>
            </div>
        </div>
        <div class="uk-width-3-4">
            <div class="uk-panel">
                <img src="images/photo2.jpg" width="600" height="400" alt="">
                <div class="uk-position-center uk-panel"><h1>4</h1></div>
            </div>
        </div>
        <div class="uk-width-3-4">
            <div class="uk-panel">
                <img src="images/photo3.jpg" width="600" height="400" alt="">
                <div class="uk-position-center uk-panel"><h1>5</h1></div>
            </div>
        </div>
    </div>

    <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
    <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>

</div>

注意 在此示例中,我们向每个项目添加了 .uk-width-3-4 类,这使得滑块看起来与幻灯片放映非常相似。


自动播放

要激活自动播放,只需将 autoplay: true 选项添加到属性。您还可以使用 autoplay-interval: 6000 设置切换幻灯片之间的间隔(以毫秒为单位)。要在悬停滑块时暂停自动播放,请使用 pause-on-hover: true

<div uk-slider="autoplay: true">…</div>

无限滚动

默认情况下,启用无限滚动。要禁用此行为,只需将 finite: true 选项添加到属性。

<div uk-slider="finite: true">…</div>

幻灯片集

要循环浏览一组幻灯片而不是单个项目,只需将 sets: true 添加到属性。

<div uk-slider="sets: true">…</div>

1

2

3

4

5

6

7

8

9

10

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider="sets: true">

    <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@m">
        <div>
            <img src="images/slider1.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>1</h1></div>
        </div>
        <div>
            <img src="images/slider2.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>2</h1></div>
        </div>
        <div>
            <img src="images/slider3.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>3</h1></div>
        </div>
        <div>
            <img src="images/slider4.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>4</h1></div>
        </div>
        <div>
            <img src="images/slider5.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>5</h1></div>
        </div>
        <div>
            <img src="images/slider1.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>6</h1></div>
        </div>
        <div>
            <img src="images/slider2.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>7</h1></div>
        </div>
        <div>
            <img src="images/slider3.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>8</h1></div>
        </div>
        <div>
            <img src="images/slider4.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>9</h1></div>
        </div>
        <div>
            <img src="images/slider5.jpg" width="400" height="600" alt="">
            <div class="uk-position-center uk-panel"><h1>10</h1></div>
        </div>
    </div>

    <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
    <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>

</div>

要浏览幻灯片,只需使用 uk-slider-item 属性。要定位幻灯片,请将每个导航项的属性设置为相应滑块项目的索引号。具有 uk-slider-item 属性的元素需要在 uk-slider 容器内。将属性设置为 nextprevious 将切换到相邻的幻灯片。

<div uk-slider>

    <div class="uk-slider-items"></div>

    <a href uk-slider-item="previous"></a>
    <a href uk-slider-item="next"></a>

    <ul>
        <li uk-slider-item="0"><a href></a></li>
        <li uk-slider-item="1"><a href></a></li>
        <li uk-slider-item="2"><a href></a></li>
    </ul>

</div>

幻灯片放映组件的灵活性使您可以使用任何其他 UIkit 组件来浏览项目。例如,可以使用幻灯片导航圆点导航缩略图导航组件来设置幻灯片放映导航的样式。

如果导航项中没有特定于项目的内容,则还可以添加 .uk-slider-nav 类,而不是手动添加导航项。它将使用 <li><a href></a></li> 作为标记自动生成其项目。当使用圆点导航时,这是一个有用的快捷方式。

<div uk-slider>

    <div class="uk-slider-items">…</div>

    <ul class="uk-slider-nav uk-dotnav"></ul>

</div>

1

2

3

4

5

6

7

8

9

10

    <div uk-slider>
    
        <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1">
    
            <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m">
                <div>
                    <img src="images/slider1.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>1</h1></div>
                </div>
                <div>
                    <img src="images/slider2.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>2</h1></div>
                </div>
                <div>
                    <img src="images/slider3.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>3</h1></div>
                </div>
                <div>
                    <img src="images/slider4.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>4</h1></div>
                </div>
                <div>
                    <img src="images/slider5.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>5</h1></div>
                </div>
                <div>
                    <img src="images/slider1.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>6</h1></div>
                </div>
                <div>
                    <img src="images/slider2.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>7</h1></div>
                </div>
                <div>
                    <img src="images/slider3.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>8</h1></div>
                </div>
                <div>
                    <img src="images/slider4.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>9</h1></div>
                </div>
                <div>
                    <img src="images/slider5.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>10</h1></div>
                </div>
            </div>
    
            <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
            <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
    
        </div>
    
        <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
    
    </div>

    注意 为了更好地显示叠加导航,请从反色组件添加 .uk-light.uk-dark 类。


    要将导航放置在滑块外部,请从定位组件previousnext 导航添加 .uk-position-center-left-out.uk-position-center-right-out 类。确保负责裁剪滑块项目的 .uk-slider-container 类也不会裁剪导航。

    <div uk-slider>
    
        <div class="uk-position-relative">
    
            <div class="uk-slider-container">
                <div class="uk-slider-items">…</div>
            </div>
    
            <a class="uk-position-center-left-out" href uk-slider-item="previous">…</a>
            <a class="uk-position-center-right-out" href uk-slider-item="next">…</a>
    
        </div>
    
        <ul class="uk-slider-nav uk-dotnav"></ul>
    
    </div>

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

      <div uk-slider>
      
          <div class="uk-position-relative">
      
              <div class="uk-slider-container uk-light">
                  <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m">
                      <div>
                          <img src="images/slider1.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>1</h1></div>
                      </div>
                      <div>
                          <img src="images/slider2.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>2</h1></div>
                      </div>
                      <div>
                          <img src="images/slider3.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>3</h1></div>
                      </div>
                      <div>
                          <img src="images/slider4.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>4</h1></div>
                      </div>
                      <div>
                          <img src="images/slider5.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>5</h1></div>
                      </div>
                      <div>
                          <img src="images/slider1.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>6</h1></div>
                      </div>
                      <div>
                          <img src="images/slider2.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>7</h1></div>
                      </div>
                      <div>
                          <img src="images/slider3.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>8</h1></div>
                      </div>
                      <div>
                          <img src="images/slider4.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>9</h1></div>
                      </div>
                      <div>
                          <img src="images/slider5.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1>10</h1></div>
                      </div>
                  </div>
              </div>
      
              <div class="uk-hidden@s uk-light">
                  <a class="uk-position-center-left uk-position-small" href uk-slidenav-previous uk-slider-item="previous"></a>
                  <a class="uk-position-center-right uk-position-small" href uk-slidenav-next uk-slider-item="next"></a>
              </div>
      
              <div class="uk-visible@s">
                  <a class="uk-position-center-left-out uk-position-small" href uk-slidenav-previous uk-slider-item="previous"></a>
                  <a class="uk-position-center-right-out uk-position-small" href uk-slidenav-next uk-slider-item="next"></a>
              </div>
      
          </div>
      
          <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
      
      </div>

      视差动画

      滑块可以使用基于其在视口中的滚动位置的无步视差动画,而不是使用导航控件的逐步动画。只需将 parallax: true 添加到属性。如果在标记中设置了导航,则它将不可点击,但它将获得当前幻灯片的活动状态。

      <div uk-slider="parallax: true">…</div>

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

        <div uk-slider="parallax: true;">
        
            <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m uk-light">
                <div>
                    <img src="images/slider1.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>1</h1></div>
                </div>
                <div>
                    <img src="images/slider2.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>2</h1></div>
                </div>
                <div>
                    <img src="images/slider3.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>3</h1></div>
                </div>
                <div>
                    <img src="images/slider4.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>4</h1></div>
                </div>
                <div>
                    <img src="images/slider5.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>5</h1></div>
                </div>
                <div>
                    <img src="images/slider1.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>6</h1></div>
                </div>
                <div>
                    <img src="images/slider2.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>7</h1></div>
                </div>
                <div>
                    <img src="images/slider3.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>8</h1></div>
                </div>
                <div>
                    <img src="images/slider4.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>9</h1></div>
                </div>
                <div>
                    <img src="images/slider5.jpg" width="400" height="600" alt="">
                    <div class="uk-position-center uk-panel"><h1>10</h1></div>
                </div>
            </div>
        
            <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
        
        </div>

        要调整视差持续时间,请设置 parallax-startparallax-end 选项。parallax-start 选项定义动画何时开始。默认值 0 表示滑块的顶部边框和视口的底部边框相交。end 选项定义动画何时结束。默认值 0 表示滑块的底部边框和视口的顶部边框相交。可以以任何尺寸单位设置值,即 vh%px% 单位与滑块的高度相关。这两个选项都允许基本数学运算符 +-

        <div uk-slider="parallax: true; parallax-start: 100%; parallax-end: 100%;">…</div>

        1

        2

        3

        4

        5

        6

        7

        8

        9

        10

          <div uk-slider="parallax: true; parallax-start: 100%; parallax-end: 100%;">
          
              <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m uk-light">
                  <div>
                      <img src="images/slider1.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>1</h1></div>
                  </div>
                  <div>
                      <img src="images/slider2.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>2</h1></div>
                  </div>
                  <div>
                      <img src="images/slider3.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>3</h1></div>
                  </div>
                  <div>
                      <img src="images/slider4.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>4</h1></div>
                  </div>
                  <div>
                      <img src="images/slider5.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>5</h1></div>
                  </div>
                  <div>
                      <img src="images/slider1.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>6</h1></div>
                  </div>
                  <div>
                      <img src="images/slider2.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>7</h1></div>
                  </div>
                  <div>
                      <img src="images/slider3.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>8</h1></div>
                  </div>
                  <div>
                      <img src="images/slider4.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>9</h1></div>
                  </div>
                  <div>
                      <img src="images/slider5.jpg" width="400" height="600" alt="">
                      <div class="uk-position-center uk-panel"><h1>10</h1></div>
                  </div>
              </div>
          
              <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
          
          </div>

          视口高度

          高度组件中的 uk-height-viewport 属性添加到滑块项目列表,将拉伸 <ul><li> 元素的高度以填充整个视口高度。由于宽度和高度现在不再由项目的内容定义,因此您必须对内容使用绝对定位。

          使用覆盖组件,使图像覆盖整个项目区域并被裁剪。来自网格组件.uk-grid-match 类匹配每个项目的直接子项的高度。这在此示例中很有用,因为子元素现在应用与列表项相同的宽度和高度。

          <div uk-slider>
              <div class="uk-slider-items uk-child-width-1-3@m uk-grid-match" uk-height-viewport="min-height: 300">
                  <div>
                      <div class="uk-cover-container">
                          <img src="" alt="" uk-cover>
                      </div>
                  </div>
              </div>
          </div>

          1

          2

          3

          4

          5

          <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider="center: true">
          
              <div class="uk-slider-items uk-grid uk-grid-match" uk-height-viewport="offset-top: true; offset-bottom: 30">
                  <div class="uk-width-3-4">
                      <div class="uk-cover-container">
                          <img src="images/photo.jpg" alt="" uk-cover>
                          <div class="uk-position-center uk-panel"><h1>1</h1></div>
                      </div>
                  </div>
                  <div class="uk-width-3-4">
                      <div class="uk-cover-container">
                          <img src="images/dark.jpg" alt="" uk-cover>
                          <div class="uk-position-center uk-panel"><h1>2</h1></div>
                      </div>
                  </div>
                  <div class="uk-width-3-4">
                      <div class="uk-cover-container">
                          <img src="images/light.jpg" alt="" uk-cover>
                          <div class="uk-position-center uk-panel"><h1>3</h1></div>
                      </div>
                  </div>
                  <div class="uk-width-3-4">
                      <div class="uk-cover-container">
                          <img src="images/photo2.jpg" alt="" uk-cover>
                          <div class="uk-position-center uk-panel"><h1>4</h1></div>
                      </div>
                  </div>
                  <div class="uk-width-3-4">
                      <div class="uk-cover-container">
                          <img src="images/photo3.jpg" alt="" uk-cover>
                          <div class="uk-position-center uk-panel"><h1>5</h1></div>
                      </div>
                  </div>
              </div>
          
              <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
              <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
          
          </div>

          注意 此示例设置为视口高度的 70%。


          内容

          滑块不限于图像。可以使用任何内容,例如文本、视频、带有文本叠加层的图像或 Ken Burns 效果。这是一个使用卡片组件的示例。

          标题

          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

          标题

          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

          标题

          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

          标题

          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

          标题

          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

            <div class="uk-slider-container-offset" uk-slider>
            
                <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1">
            
                    <div class="uk-slider-items uk-child-width-1-2@s uk-grid">
                        <div>
                            <div class="uk-card uk-card-default">
                                <div class="uk-card-media-top">
                                    <img src="images/photo.jpg" width="1800" height="1200" alt="">
                                </div>
                                <div class="uk-card-body">
                                    <h3 class="uk-card-title">Headline</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="uk-card uk-card-default">
                                <div class="uk-card-media-top">
                                    <img src="images/dark.jpg" width="1800" height="1200" alt="">
                                </div>
                                <div class="uk-card-body">
                                    <h3 class="uk-card-title">Headline</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="uk-card uk-card-default">
                                <div class="uk-card-media-top">
                                    <img src="images/light.jpg" width="1800" height="1200" alt="">
                                </div>
                                <div class="uk-card-body">
                                    <h3 class="uk-card-title">Headline</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="uk-card uk-card-default">
                                <div class="uk-card-media-top">
                                    <img src="images/photo2.jpg" width="1800" height="1200" alt="">
                                </div>
                                <div class="uk-card-body">
                                    <h3 class="uk-card-title">Headline</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                                </div>
                            </div>
                        </div>
                        <div>
                            <div class="uk-card uk-card-default">
                                <div class="uk-card-media-top">
                                    <img src="images/photo3.jpg" width="1800" height="1200" alt="">
                                </div>
                                <div class="uk-card-body">
                                    <h3 class="uk-card-title">Headline</h3>
                                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p>
                                </div>
                            </div>
                        </div>
                    </div>
            
                    <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
                    <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
            
                </div>
            
                <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
            
            </div>

            注意 由于滑块效果需要裁剪容器,内容项目的阴影也会被裁剪。要加宽容器以防止阴影被裁剪,请添加 .uk-slider-container-offset 类。或者,如果您的内容项目具有阴影,则使用 uk-slider="center: true" 模式。


            内容叠加

            使用定位组件添加内容叠加层。它允许您将内容放置在幻灯片中的任何位置。

            <div uk-slider>
                <div class="uk-slider-items">
                    <div>
                        <img src="" width="" height="" alt="">
                        <div class="uk-position-center">
            
                            <!-- The content goes here -->
            
                        </div>
                    </div>
                </div>
            </div>

            注意 要使您的内容更好地适应每张图像的可见性,请从反色组件添加 .uk-light.uk-dark 类,或者使用覆盖向覆盖框添加任何样式。

            1

            2

            3

            4

            5

            6

            7

            8

            9

            10

            <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider>
            
                <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m">
                    <div>
                        <img src="images/slider1.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>1</h1></div>
                    </div>
                    <div>
                        <img src="images/slider2.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>2</h1></div>
                    </div>
                    <div>
                        <img src="images/slider3.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>3</h1></div>
                    </div>
                    <div>
                        <img src="images/slider4.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>4</h1></div>
                    </div>
                    <div>
                        <img src="images/slider5.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>5</h1></div>
                    </div>
                    <div>
                        <img src="images/slider1.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>6</h1></div>
                    </div>
                    <div>
                        <img src="images/slider2.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>7</h1></div>
                    </div>
                    <div>
                        <img src="images/slider3.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>8</h1></div>
                    </div>
                    <div>
                        <img src="images/slider4.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>9</h1></div>
                    </div>
                    <div>
                        <img src="images/slider5.jpg" width="400" height="600" alt="">
                        <div class="uk-position-center uk-panel"><h1>10</h1></div>
                    </div>
                </div>
            
                <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
                <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
            
            </div>

            内容视差

            向幻灯片中的任何元素添加 uk-slider-parallax 属性,以便将其与滑块动画一起动画化。为要动画化的每个 CSS 属性添加一个带有所需动画值的选项。至少定义一个开始值和一个结束值。可以通过传递用逗号分隔的两个值来完成此操作。

            此功能继承自视差组件,它允许根据滑块动画的滚动位置动画化 CSS 属性。查看可以动画化的可能的属性

            <div uk-slider>
                <div class="uk-slider-items">
                    <div>
                        <img src="" width="" height="" alt="">
                        <div class="uk-position-center">
            
                            <div uk-slider-parallax="x: 100,-100">
            
                                <!-- The content goes here -->
            
                            </div>
            
                        </div>
                    </div>
                </div>
            </div>

            在上面的示例中,内容将从 100 开始,并在幻灯片移入时动画到 0 的一半。当幻灯片再次开始移出时,内容将继续动画到 -100。之所以可行,是因为开始值和结束值具有相同的距离。对于不同的距离,需要三个值:开始(幻灯片移入)、中间(幻灯片居中)、结束(幻灯片移出)。

            <div uk-slider-parallax="x: 300,0,-100">…</div>

            下一个示例定义了不同的进入和退出动画。内容通过从 100 移动到 0 滑入,并从 1 渐变到 0 渐出。

            <div uk-slider-parallax="x: 100,0,0; opacity: 1,1,0">…</div>

            标题

            Lorem ipsum dolor sit amet.

            标题

            Lorem ipsum dolor sit amet.

            标题

            Lorem ipsum dolor sit amet.

            标题

            Lorem ipsum dolor sit amet.

            标题

            Lorem ipsum dolor sit amet.

            <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider>
            
                <div class="uk-slider-items uk-grid">
                    <div class="uk-width-4-5">
                        <div class="uk-panel">
                            <img src="images/photo.jpg" width="1800" height="1200" alt="">
                            <div class="uk-position-center uk-text-center">
                                <h2 uk-slider-parallax="x: 100,-100">Heading</h2>
                                <p uk-slider-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-4-5">
                        <div class="uk-panel">
                            <img src="images/dark.jpg" width="1800" height="1200" alt="">
                            <div class="uk-position-center uk-text-center">
                                <h2 uk-slider-parallax="x: 100,-100">Heading</h2>
                                <p uk-slider-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-4-5">
                        <div class="uk-panel">
                            <img src="images/light.jpg" width="1800" height="1200" alt="">
                            <div class="uk-position-center uk-text-center">
                                <h2 uk-slider-parallax="x: 100,-100">Heading</h2>
                                <p uk-slider-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-4-5">
                        <div class="uk-panel">
                            <img src="images/photo2.jpg" width="1800" height="1200" alt="">
                            <div class="uk-position-center uk-text-center">
                                <h2 uk-slider-parallax="x: 100,-100">Heading</h2>
                                <p uk-slider-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-4-5">
                        <div class="uk-panel">
                            <img src="images/photo3.jpg" width="1800" height="1200" alt="">
                            <div class="uk-position-center uk-text-center">
                                <h2 uk-slider-parallax="x: 100,-100">Heading</h2>
                                <p uk-slider-parallax="x: 200,-200">Lorem ipsum dolor sit amet.</p>
                            </div>
                        </div>
                    </div>
                </div>
            
                <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
                <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
            
            </div>

            内容过渡

            clsActivated: uk-transition-active 添加到属性,以自动触发过渡组件中幻灯片内的过渡类。与视差效果相反,过渡不附加到滑块动画,而是在滑块动画之后独立开始播放。

            <div uk-slider="clsActivated: uk-transition-active">
                <div class="uk-slider-items">
                    <div>
                        <img src="" width="" height="" alt="">
                        <div class="uk-position-bottom">
            
                            <div class="uk-transition-slide-bottom">
            
                                <!-- The content goes here -->
            
                            </div>
            
                        </div>
                    </div>
                </div>
            </div>

            覆盖组件一起,内容过渡用于为滑块构建经典标题。

            底部

            Lorem ipsum dolor sit amet, consectetur adipiscing elit.

            底部

            Lorem ipsum dolor sit amet, consectetur adipiscing elit.

            底部

            Lorem ipsum dolor sit amet, consectetur adipiscing elit.

            底部

            Lorem ipsum dolor sit amet, consectetur adipiscing elit.

            底部

            Lorem ipsum dolor sit amet, consectetur adipiscing elit.

            <div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slider="clsActivated: uk-transition-active; center: true">
            
                <div class="uk-slider-items uk-grid">
                    <div class="uk-width-3-4">
                        <div class="uk-panel">
                            <img src="images/photo.jpg" width="1800" height="1200" alt="">
                            <div class="uk-overlay uk-overlay-primary uk-position-bottom uk-text-center uk-transition-slide-bottom">
                                <h3 class="uk-margin-remove">Bottom</h3>
                                <p class="uk-margin-remove">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-3-4">
                        <div class="uk-panel">
                            <img src="images/dark.jpg" width="1800" height="1200" alt="">
                            <div class="uk-overlay uk-overlay-primary uk-position-bottom uk-text-center uk-transition-slide-bottom">
                                <h3 class="uk-margin-remove">Bottom</h3>
                                <p class="uk-margin-remove">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-3-4">
                        <div class="uk-panel">
                            <img src="images/light.jpg" width="1800" height="1200" alt="">
                            <div class="uk-overlay uk-overlay-primary uk-position-bottom uk-text-center uk-transition-slide-bottom">
                                <h3 class="uk-margin-remove">Bottom</h3>
                                <p class="uk-margin-remove">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-3-4">
                        <div class="uk-panel">
                            <img src="images/photo2.jpg" width="1800" height="1200" alt="">
                            <div class="uk-overlay uk-overlay-primary uk-position-bottom uk-text-center uk-transition-slide-bottom">
                                <h3 class="uk-margin-remove">Bottom</h3>
                                <p class="uk-margin-remove">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            </div>
                        </div>
                    </div>
                    <div class="uk-width-3-4">
                        <div class="uk-panel">
                            <img src="images/photo3.jpg" width="1800" height="1200" alt="">
                            <div class="uk-overlay uk-overlay-primary uk-position-bottom uk-text-center uk-transition-slide-bottom">
                                <h3 class="uk-margin-remove">Bottom</h3>
                                <p class="uk-margin-remove">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            </div>
                        </div>
                    </div>
                </div>
            
                <a class="uk-position-center-left uk-position-small uk-hidden-hover" href uk-slidenav-previous uk-slider-item="previous"></a>
                <a class="uk-position-center-right uk-position-small uk-hidden-hover" href uk-slidenav-next uk-slider-item="next"></a>
            
            </div>

            悬停时切换

            要在悬停时切换过渡,请使用过渡组件中的 .uk-transition-toggle 类和 tabindex="0"。当元素被悬停或聚焦时,这将触发过渡。

            <div uk-slider>
                <div class="uk-slider-items">
                    <div class="uk-transition-toggle" tabindex="0">
                        <img src="" width="" height="" alt="">
                        <div class="uk-position-bottom">
            
                            <div class="uk-transition-slide-bottom">
            
                                <!-- The content goes here -->
            
                            </div>
            
                        </div>
                    </div>
                </div>
            </div>

            1

            2

            3

            4

            5

            6

            7

            8

            9

            10

              <div uk-slider>
              
                  <div class="uk-slider-items uk-child-width-1-2 uk-child-width-1-3@s uk-child-width-1-4@m uk-light">
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider1.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">1</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider2.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">2</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider3.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">3</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider4.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">4</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider5.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">5</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider1.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">6</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider2.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">7</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider3.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">8</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider4.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">9</h1></div>
                      </div>
                      <div class="uk-transition-toggle" tabindex="0">
                          <img src="images/slider5.jpg" width="400" height="600" alt="">
                          <div class="uk-position-center uk-panel"><h1 class="uk-transition-slide-bottom-small">10</h1></div>
                      </div>
                  </div>
              
                  <ul class="uk-slider-nav uk-dotnav uk-flex-center uk-margin"></ul>
              
              </div>

              组件选项

              可以将以下任何选项应用于组件属性。用分号分隔多个选项。了解更多

              选项 默认值 描述
              自动播放 布尔值 false 滑块自动播放。
              自动播放间隔 数字 7000 自动播放模式下切换幻灯片之间的延迟。
              居中 布尔值 false 将活动幻灯片居中。
              可拖拽 布尔值 true 启用指针拖动。
              缓动 字符串 ease 动画缓动效果(CSS timing functions 或 cubic-bezier)。
              有限 布尔值 false 禁用无限滑动。
              索引 数字 0 要显示的滑块项目。基于 0 的索引。
              活动 字符串 全部 要应用过渡活动类的滑块项目/多个项目(全部、第一个)。
              悬停时暂停 布尔值 true 悬停时暂停自动播放模式。
              集合 布尔值 false 按集合滑动。
              速度 数字 1 动画速度(像素/毫秒)。

              JavaScript

              了解更多关于 JavaScript 组件 的信息。

              初始化

              UIkit.slider(element, options);

              事件

              以下事件将在附加此组件的元素上触发

              名称 描述
              beforeitemshow 在显示项目之前触发。
              itemshow 在显示项目之后触发。
              itemshown 在项目显示动画完成后触发。
              beforeitemhide 在隐藏项目之前触发。
              itemhide 在项目隐藏动画开始后触发。
              itemhidden 在项目隐藏动画完成后触发。

              方法

              以下方法可用于组件

              显示

              UIkit.slider(element).show(index);

              显示滑块项目。

              开始自动播放

              UIkit.slider(element).startAutoplay();

              启动滑块自动播放。

              停止自动播放

              UIkit.slider(element).stopAutoplay();

              停止滑块自动播放。


              可访问性

              滑块组件遵循 轮播 WAI-ARIA 设计模式,并自动设置适当的 WAI-ARIA 角色、状态和属性。

              选项卡导航遵循 选项卡模式

              上一个/下一个导航遵循 按钮模式

              键盘交互

              当滑块组件中的任何元素获得焦点时,自动播放停止。可以使用以下键通过键盘访问选项卡导航。

              国际化

              滑块组件使用以下翻译字符串。了解更多关于 翻译组件 的信息。

              默认值 描述
              next 下一张幻灯片 下一个幻灯片按钮的 aria-label
              previous 上一张幻灯片 上一个幻灯片按钮的 aria-label
              slideX 幻灯片 %s 分页幻灯片按钮的 aria-label
              slideLabel %s / %s 幻灯片的 aria-label