[英]Link to a specific slide in a Bootstrap carousel
I've been attempting to setup a way to link to certain slides within my bootstrap carousel.我一直在尝试设置一种方法来链接到我的引导轮播中的某些幻灯片。 I've attempted all of the solutions from here , including the both the javascript ones and non-javascript ones.
我已经尝试了这里的所有解决方案,包括 javascript 和非 JavaScript 的。 I've attempted using normal anchors, ordered/unordered lists, and buttons, both inside and outside the main carousel div.
我尝试在主轮播 div 内部和外部使用普通锚点、有序/无序列表和按钮。
So far it seems I can't get any variation of data-slide-to, data-slide, or anything else to work.到目前为止,我似乎无法获得数据幻灯片、数据幻灯片或其他任何工作的任何变化。 The next slide and previous slide buttons, however, work perfectly fine.
但是,下一张幻灯片和上一张幻灯片按钮可以正常工作。 I just can't seem to link to a specific slide.
我似乎无法链接到特定幻灯片。 Are these methods outdated with the latest version of bootstrap, or is there something I'm missing?
这些方法是否与最新版本的引导程序过时了,或者我缺少什么?
My most recent iteration is below:我最近的迭代如下:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"><a href="#myCarousel" data-target="#myCarousel" data-slide-to="0" class="active">Slide 1</a></li>
<li data-target="#myCarousel" data-slide-to="1"><a href="#myCarousel" data-slide-to="1" data-target="#myCarousel" class="active">Slide 2</a></li>
<li data-target="#myCarousel" data-slide-to="2"><a href="#myCarousel" data-slide-to="2" data-target="#myCarousel" class="active">Slide 3</a></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
Content 1
</div>
<div class="carousel-item">
Content 2
</div>
<div class="carousel-item">
Content 3
</div>
</div>
</div>
If you refer to the latest version of Bootstrap ie v5, you have to use data-bs-slide-to
property in the indicators, and also you have to give custom styles to fit the text inside them.如果您参考最新版本的 Bootstrap 即 v5,您必须在指标中使用
data-bs-slide-to
属性,并且您必须自定义 styles 以适应其中的文本。 Here is the page for reference -这是供参考的页面-
https://getbootstrap.com/docs/5.0/components/carousel/#with-indicators https://getbootstrap.com/docs/5.0/components/carousel/#with-indicators
You can do something like this -你可以做这样的事情 -
.carousel-item { height: 200px; }.carousel-indicators { bottom: -50px; }.carousel-indicators.carousel-indicators-numbers.indicators { text-indent: 0; width: 70px; text-align: center; height: 70px; border: none; display: flex; align-items: center; justify-content: center; line-height: 30px; color: white; font-size: 20px; background-color: #999; transition: all 0.25s ease; }.carousel-indicators-numbers.indicators.active, .carousel-indicators-numbers.indicators:hover { background-color: #337ab7; }
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel"> <ol class="carousel-indicators carousel-indicators-numbers"> <li class="active indicators" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-current="true" aria-label="Slide 1">Slide 3</li> <li class="indicators" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2">Slide 2</li> <li class="indicators" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" aria-label="Slide 3">Slide 1</li> </ol> <div class="carousel-inner"> <div class="carousel-item active"> Content 1 </div> <div class="carousel-item"> Content 2 </div> <div class="carousel-item"> Content 3 </div> </div> </div>
Hope this helps, let me know if you're facing any issue.希望这会有所帮助,如果您遇到任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.