Bootstrap 4 Modal 在 Slick 轮播中不工作 div

Bootstrap 4 Modal is not working Inside Slick carousel div

经过大量搜索,进行了大量调试,我发现在 slick carousel div 中,bootstrap 模式没有显示。只显示灰色后退。

这是代码:在这段代码中,我们从数据库中获取详细信息并使用 slick 显示图像,当有人点击这些图像时,它将打开该图像的模式.但除此之外一切都很好。如何在 slick div.

中调用模态

提前致谢

 <?php
 $ush = $mysqli->prepare("SELECT company_id, img, name from list");
 $ush->execute();
 $ush->store_result();
 $ush->bind_result($u_bid, $u_bimg,$u_bname);
 ?>
<div class="company-logo">
<?php
while($ush->fetch()){
?>
<div>
  <a href="#<?php echo $u_bid;?>" data-toggle="modal" data-target="#<?php echo $u_bid;?>"><img 
 src="data:image/png;base64,<?php echo base64_encode($u_bimg); ?>" height="80px" width="80px"></a>
<!-- Modal -->
 <div class="modal" id="<?php echo $u_bid;?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo $u_bid;?>" aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered modal-md" role="document">
     <div class="modal-content">
       <div class="modal-body">
         <div class="container text-center">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><h3><b>X</b></h3></span>
          </button>
          <h3><?php echo $u_bname;?></h3> 
         </div>
       </div>
      </div>
    </div>
   </div>
 </div>
 <?php
 }
   $ush->close();
 ?>
 </div>
 <script type="text/javascript">
     $(document).ready(function(){
      $('.company-logo').slick({
              dots:true,
              infinite:false,
              speed:300,
              slidesToShow:14,
              slidesToScroll:14,
              arrows:false,
              responsive:[{
                      breakpoint:768,
                      settings:{
                                slidesToShow:4,
                                slidesToScroll:4
                               }
                     }]
              })
           });
  </script>

我认为你应该像这样将模态代码部分移到轮播部分之外:

<?php
 $ush = $mysqli->prepare("SELECT company_id, img, name from list");
 $ush->execute();
 $ush->store_result();
 $ush->bind_result($u_bid, $u_bimg,$u_bname);
 
$carousel_content = '';
$modal_content = '';
while($ush->fetch()){
 $carousel_content .= '<div>
  <a href="#'.$u_bid.'" data-toggle="modal" data-target="#'.$u_bid.'"><img 
 src="data:image/png;base64,'.base64_encode($u_bimg).'" height="80px" width="80px"></a>    
 </div>';
 $modal_content .= '<!-- Modal -->
 <div class="modal" id="'.$u_bid.'" tabindex="-1" role="dialog" aria-labelledby="'.$u_bid.'" aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered modal-md" role="document">
     <div class="modal-content">
       <div class="modal-body">
         <div class="container text-center">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><h3><b>X</b></h3></span>
          </button>
          <h3>'.$u_bname.'</h3> 
         </div>
       </div>
      </div>
    </div>
   </div>';
?>

 <?php
 }
   $ush->close();
 ?>
 <div class="company-logo"><?=$carousel_content?></div>

 <div id="modal_contents"><?=$modal_content?></div>

 <script type="text/javascript">
     $(document).ready(function(){
      $('.company-logo').slick({
              dots:true,
              infinite:false,
              speed:300,
              slidesToShow:14,
              slidesToScroll:14,
              arrows:false,
              responsive:[{
                      breakpoint:768,
                      settings:{
                                slidesToShow:4,
                                slidesToScroll:4
                               }
                     }]
              })
           });
  </script>