当我将视频添加到幻灯片时,我的 Bootstrap Carousel 没有改变?

问题描述

我有一个 bootstrap carousel,当我只包含图像时它可以完美运行,但是一旦我添加了视频,我的指示器就不起作用并且我无法点击其余的幻灯片?有谁知道我做错了什么?这是我的代码,带有一点狡猾的 PHP

echo "<div class='carousel-item";
  if ($caroselCount == "1") { echo " active"; }
echo "'>";

if($extraPicDetails['file_type'] == "image") {
  echo "<img src='Members/".$Details['file_name']."' alt='' style='margin: auto; display: block; background-color: #ffffff;'>";
}
elseif($extraPicDetails['file_type'] == "video") {
  echo "<video src='Members/".$Details['file_name']."' loop autoplay muted playsinline width='100%' style='display: block;'>";
}

echo "</div>";
$caroselCount = "0";

如果我只是循环浏览一堆图片,一切都很好,但是如果有几张图片一个视频......不!无法点击幻灯片,有人可以帮我吗?

这是渲染的代码

<div class="carousel-inner">
<div class='carousel-item active'>
<video src='Members/44_Pic1_ezgifcomgifmaker.mp4' loop autoplay muted playsinline width='100%' style='display: block;'>
</div>
<div class='carousel-item'>
<img src='Members/44_Pic2_Polish_20200814_165321683.jpg' alt='' style='margin: auto; display: block; background-color: #ffffff;'>
</div>
<div class='carousel-item'>
<img src='Members/44_Pic1_image.jpg' alt='' style='margin: auto; display: block; background-color: #ffffff;'>
</div>
</div>

解决方法

我试图重现您的错误,但一切正常。我从 pixabay 下载了一个视频和图像,并通过 cdn 链接加载了 bootstrap 4。我没有使用内联 css,而是使用引导类 img-fluid 使媒体更适合轮播,我在示例中禁用了指示器。

在我测试的代码下面:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-12">

            <div id="demo" class="carousel slide" data-ride="carousel">

                <!-- Indicators -->
                <!--        <ul class="carousel-indicators">-->
                <!--            <li data-target="#demo" data-slide-to="0" class="active"></li>-->
                <!--            <li data-target="#demo" data-slide-to="1"></li>-->
                <!--            <li data-target="#demo" data-slide-to="2"></li>-->
                <!--        </ul>-->

                <!-- The slideshow -->
                <div class="carousel-inner">

                    <div class="carousel-inner">
                        <div class='carousel-item active'>
                            <video src='media/Golden - 48569.mp4' loop autoplay muted playsinline class="img-fluid">
                        </div>
                        <div class='carousel-item'>
                            <img src='media/20201102_14%20-%20Foto.jpg' alt='' class="img-fluid">
                        </div>
                        <div class='carousel-item'>
                            <img src='media/20201102_17%20-%20Fotoe.jpg' alt='' class="img-fluid">
                        </div>
                    </div>
                </div>

                <!-- Left and right controls -->
                <a class="carousel-control-prev" href="#demo" data-slide="prev">
                    <span class="carousel-control-prev-icon"></span>
                </a>
                <a class="carousel-control-next" href="#demo" data-slide="next">
                    <span class="carousel-control-next-icon"></span>
                </a>

            </div>

        </div>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>