问题
So I'm trying to have a carousel with 4 videos in it and am having some issues and can't see why. First of all I can only switch videos by using the circles at the bottom middle of the screen, I can't click on the left or right or the video to switch. When I do switch moving to the left works fine but when I go to the right the play button appears where the left indicator should be and when I play the video it pops back into the middle. Any help would be appreciated as I'm fairly stumped here. Here's my code. Thanks in advance.
<div id="help--video-help-carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#help--video-help-carousel" data-slide-to="0" class="active"></li>
<li data-target="#help--video-help-carousel" data-slide-to="1"></li>
<li data-target="#help--video-help-carousel" data-slide-to="2"></li>
<li data-target="#help--video-help-carousel" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<video width="900" height="600" border="5" controls="controls">
<source src="help1.mp4" type="video/mp4">
</video>
<div class="carousel-caption">
<h3 class="h3-responsive">Help 1</h3>
</div>
</div>
<div class="item">
<video width="900" height="600" controls="controls">
<source src="help2.mp4" type="video/mp4">
</video>
<div class="carousel-caption">
<h3 class="h3-responsive">Help 2y</h3>
</div>
</div>
<div class="item">
<video width="900" height="600" controls="controls">
<source src="help3.mp4" type="video/mp4">
</video>
<div class="carousel-caption">
<h3 class="h3-responsive">Help 3</h3>
</div>
</div>
<div class="item">
<video width="900" height="600" controls="controls">
<source src="help4.mp4" type="video/mp4">
</video>
<div class="carousel-caption d-none d-md-block">
</div>
<div class="carousel-caption">
<h3 class="h3-responsive">Help 4</h3>
</div>
</div>
<a class="carousel-control-prev" href="#help--video-help-carousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#help--video-help-carousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
回答1:
Johan was correct about item
needing to be carousel-item
. That fixed the code for me. Additionally, wrapping the carousel in a container seems to fix the controls. You may want to add a bottom margin to the controls, captions, and indicators as well.
<div class="container-fluid col-8 offset-2">
<div id="help--video-help-carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators" style="margin-bottom: 60px;">
<li data-target="#help--video-help-carousel" data-slide-to="0" class="active"></li>
<li data-target="#help--video-help-carousel" data-slide-to="1"></li>
<li data-target="#help--video-help-carousel" data-slide-to="2"></li>
<li data-target="#help--video-help-carousel" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<video width="900" height="600" border="5" controls="controls">
<source src="help1.mp4" type="video/mp4">
</video>
<div class="carousel-caption d-none d-md-block" style="margin-bottom: 60px;">
<h3 class="h3-responsive">Help 1</h3>
</div>
</div>
<div class="carousel-item">
<video width="900" height="600" controls="controls">
<source src="help2.mp4" type="video/mp4">
</video>
<div class="carousel-caption d-none d-md-block" style="margin-bottom: 60px;">
<h3 class="h3-responsive">Help 2y</h3>
</div>
</div>
<div class="carousel-item">
<video width="900" height="600" controls="controls">
<source src="help3.mp4" type="video/mp4">
</video>
<div class="carousel-caption d-none d-md-block" style="margin-bottom: 60px;">
<h3 class="h3-responsive">Help 3</h3>
</div>
</div>
<div class="carousel-item">
<video width="900" height="600" controls="controls">
<source src="help4.mp4" type="video/mp4">
</video>
<div class="carousel-caption d-none d-md-block" style="margin-bottom: 60px;">
<h3 class="h3-responsive">Help 4</h3>
</div>
</div>
<a class="carousel-control-prev" href="#help--video-help-carousel" role="button" data-slide="prev" style="margin-bottom: 60px;">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#help--video-help-carousel" role="button" data-slide="next" style="margin-bottom: 60px;">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
Screenshot of carousel
回答2:
In Bootstrap v4.x (latest) the individual carousel elements class is not 'item' it's 'carousel-item'.
Also you've set a class 'd-none d-md-block' on just one of the elements which is inconsistent at best. You might want to look into Bootstraps use of alignment in the carousel https://getbootstrap.com/docs/4.1/components/carousel/#slides-only where they use 'd-block' (class="d-block w-100") on all elements in the example.
Haven't tested but that might be it.
来源:https://stackoverflow.com/questions/51152277/bootstrap-video-carousel-play-button-left-right-indicators-not-appearing