在有限空間內,循環(huán)播放同一類型的圖片、文字等內容
適用廣泛的基礎用法
結合使用Carousel
和Carousel.Item
標簽就得到了一個走馬燈?;脽羝膬热菔侨我獾模枰旁?code>Carousel.Item標簽中。默認情況下,在鼠標 hover 底部的指示器時就會觸發(fā)切換。通過設置trigger
屬性為click
,可以達到點擊觸發(fā)的效果。
render() {
return (
<div className="demo-1 small">
<div className="block">
<span className="demonstration">默認 Hover 指示器觸發(fā)</span>
<Carousel height="150px">
{
[1,2,3,4].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
<div className="block">
<span className="demonstration">Click 指示器觸發(fā)</span>
<Carousel trigger="click" height="150px">
{
[1,2,3,4].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
</div>
)
}
可以將指示器的顯示位置設置在容器外部
indicator-position
屬性定義了指示器的位置。默認情況下,它會顯示在走馬燈內部,設置為outside
則會顯示在外部;設置為none
則不會顯示指示器。
render() {
return (
<div className="demo-2 medium">
<Carousel indicatorPosition="outside">
{
[1,2,3,4].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
)
}
可以設置切換箭頭的顯示時機
arrow
屬性定義了切換箭頭的顯示時機。默認情況下,切換箭頭只有在鼠標 hover 到走馬燈上時才會顯示;若將arrow
設置為always
,則會一直顯示;設置為never
,則會一直隱藏。
render() {
return (
<div className="demo-3 medium">
<Carousel interval="5000" arrow="always">
{
[1,2,3,4].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
)
}
當頁面寬度方向空間空余,但高度方向空間匱乏時,可使用卡片風格
將type
屬性設置為card
即可啟用卡片模式。從交互上來說,卡片模式和一般模式的最大區(qū)別在于,可以通過直接點擊兩側的幻燈片進行切換。
render() {
return (
<div className="demo-4 medium">
<Carousel interval="4000" type="card" height="200px">
{
[1,2,3,4,5,6].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
)
}
統(tǒng)一卡片大小
將type
屬性設置為flatcard
即可啟用扁平卡片模式。從交互上來說,卡片模式和一般模式的最大區(qū)別在于,可以通過直接點擊兩側的幻燈片進行切換。
render() {
return (
<div className="demo-4 medium">
<Carousel interval="4000" type="flatcard" height="200px">
{
[1,2,3,4,5,6].map((item, index) => {
return (
<Carousel.Item key={index}>
<h3>{item}</h3>
</Carousel.Item>
)
})
}
</Carousel>
</div>
)
}
參數(shù) | 說明 | 類型 | 可選值 | 默認值 |
---|---|---|---|---|
height | 走馬燈的高度 | number | — | 300 |
initialIndex | 初始狀態(tài)激活的幻燈片的索引,從 0 開始 | number | — | 0 |
trigger | 指示器的觸發(fā)方式 | string | click | — |
autoplay | 是否自動切換 | boolean | — | true |
interval | 自動切換的時間間隔,單位為毫秒 | number | — | 3000 |
indicatorPosition | 指示器的位置 | string | outside/none | — |
arrow | 切換箭頭的顯示時機 | string | always/hover/never | hover |
type | 走馬燈的類型 | string | card/flatcard | — |
事件名稱 | 說明 | 回調參數(shù) |
---|---|---|
onChange | 幻燈片切換時觸發(fā) | 目前激活的幻燈片的索引,原幻燈片的索引 |
方法名 | 說明 | 參數(shù) |
---|---|---|
setActiveItem | 手動切換幻燈片 | 需要切換的幻燈片的索引,從 0 開始;或相應 Carousel.Item 的 name 屬性值 |
prev | 切換至上一張幻燈片 | — |
next | 切換至下一張幻燈片 | — |
參數(shù) | 說明 | 類型 | 可選值 | 默認值 |
---|---|---|---|---|
name | 幻燈片的名字,可用作 setActiveItem 的參數(shù) |
string | — | — |
更多建議: