[英]Bootstrap v4 Carousel Not Initializing
Im trying to get a Bootstrap v4 Slider to work. 我正在尝试让Bootstrap v4滑块正常工作。
Its supposed to have text to the right of the slider and this text is meant to change with each slide. 它应该在滑块的右边有文本,并且该文本随每张幻灯片而变化。
I have added in the required CSS/JS but the slider will not initialize. 我已经添加了所需的CSS / JS,但滑块不会初始化。
Link to JS FIDDLE 链接到JS FIDDLE
My JS: 我的JS:
<script>
$( document ).ready(function() {
//set here the speed to change the slides in the carousel
$('#features').carousel({});
//Loads the html to each slider. Write in the "div id="slide-content-x" what you want to show in each slide
$('#carousel-text').html($('#slide-content-0').html());
// When the carousel slides, auto update the text
$('#features').on('slid.bs.carousel', function (e) {
var id = $('.item.active').data('slide-number');
$('#carousel-text').html($('#slide-content-'+id).html());
});
});
</script>
looks like your markup in the example is not sufficient. 看起来您在示例中的标记是不够的。
you have one .carousel-inner
div container without .carousel-item
inside. 您有一个.carousel-inner
div容器, .carousel-inner
没有.carousel-item
。 which of course is just one slide. 当然,那只是一张幻灯片。
try to follow the example provided by the bootstrap documentation 尝试遵循引导文档提供的示例
put your #slide-content-x
containers inside several .carousel-inner
div's and remove your JS workaround for that. 将您的#slide-content-x
容器放入多个.carousel-inner
div .carousel-inner
并删除您的JS解决方法。
you do not need any JS. 您不需要任何JS。 it's self-initializing. 它是自我初始化的。
see my working example here: https://jsfiddle.net/y8h5oqfw/2/ 在这里查看我的工作示例: https : //jsfiddle.net/y8h5oqfw/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.