简体   繁体   English

引导图像模态弹出式jQuery PHP

[英]bootstrap image modal popup jquery php

I am building a modal to display from my image carousel. 我正在建立从我的图片轮播展示的模式。 But it doesn't work - pop up come out, but with no image. 但这不起作用-弹出窗口出来,但是没有图像。 I need help to see what's wrong with my code here. 我需要帮助,以查看此处的代码有什么问题。 It is not displaying any image at all, even I don't know what's causing it. 它根本不显示任何图像,即使我不知道是什么原因。 What I want to achieve is, to pop up image that click on product menu. 我要实现的是,弹出单击产品菜单上的图像。

The images are in a view that will call the modal: 图像处于将调用模式的视图中:

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

  <div class="carousel-inner">

    <?php 
$banyak = 0;
$id = $results->id;
$barangNama = $results->nama;
$barangHarga1 = $results->harga;
$barangGambar = $results->gambar;
$barangMerk = $results->merk;
$barangCategory = $results->category;
$barangTipe = $results->tipe;
$barangDeskripsi = $results->deskripsi;

$barangHarga = number_format($barangHarga1);

$newGambar = explode(',',$barangGambar);
//print_r($newGambar);
?>

    <?php 
$w = 0;
for($i = 0; $i < count($newGambar); $i++) {


if($w % 4 == 0){
$banyak++;
}
$w++;
//echo $banyak;
?>
    <div class="item <?php if($i == 0){echo "active";} ?>" data-thumb="<?php echo $banyak-1; ?>">
      /* this is where i call the modal */  <a href="#" data-toggle="modal" data-target="#image-gallery">
      <img src="<?php echo base_url(); ?>assets/images/product_picture/<?php echo $newGambar[$i]; ?>" alt="asda">
      </a>    
    </div>
    <?php   
}
?>
    <a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#carousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
  </div>
</div>

modal to show pop up image : 显示弹出图像的模态:

<!-- Modal -->
<div class="modal fade" id="image-gallery" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">X</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="image-gallery-title"></h4>
      </div>
      <div class="modal-body">
        <img id="image-gallery-image" class="img-responsive" src="">
      </div>
      <div class="modal-footer">

        <div class="col-md-2">
          <button type="button" class="btn btn-primary" id="show-previous-image">Previous</button>
        </div>

        <div class="col-md-8 text-justify" id="image-gallery-caption">

        </div>

        <div class="col-md-2">
          <button type="button" id="show-next-image" class="btn btn-default">Next</button>
        </div>
      </div>
    </div>
  </div>
</div>

script: 脚本:

$(document).ready(function(){

  loadGallery(true, 'a.thumbnail');

  //This function disables buttons when needed
  function disableButtons(counter_max, counter_current){
    $('#show-previous-image, #show-next-image').show();
    if(counter_max == counter_current){
      $('#show-next-image').hide();
    } else if (counter_current == 1){
      $('#show-previous-image').hide();
    }
  }
  function loadGallery(setIDs, setClickAttr){
    var current_image,
        selector,
        counter = 0;

    $('#show-next-image, #show-previous-image').click(function(){
      if($(this).attr('id') == 'show-previous-image'){
        current_image--;
      } else {
        current_image++;
      }

      selector = $('[data-image-id="' + current_image + '"]');
      updateGallery(selector);
    });

    function updateGallery(selector) {
      var $sel = selector;
      current_image = $sel.data('image-id');
      $('#image-gallery-caption').text($sel.data('caption'));
      $('#image-gallery-title').text($sel.data('title'));
      $('#image-gallery-image').attr('src', $sel.data('image'));
      disableButtons(counter, $sel.data('image-id'));
    }

    if(setIDs == true){
      $('[data-image-id]').each(function(){
        counter++;
        $(this).attr('data-image-id',counter);
      });
    }
    $(setClickAttr).on('click',function(){
      updateGallery($(this));
    });
  }
});

Guess you have commented out the output? 猜猜您已经注释掉输出了吗?

<?php 
  $w = 0;
  for ($i = 0; $i < count($newGambar); $i++) {
    if ($w % 4 == 0){
    $banyak++;
  }
  $w++;
  echo $banyak;
?>

it is because of z-index value.inspect the web page.heck the z-index of carousel.Most developers put the -9999px and 9999px values or similar in their code. 这是因为z-index的值。检查网页。检查轮播的z-index。大多数开发人员在其代码中放置了-9999px和9999px值或类似值。

Adjust your z-index values so that modal box and it's container comes on top of carousel. 调整z-index值,使模式框及其容器位于转盘顶部。

bootstrap modal css is inside bootstrap.css bootstrap modal css在bootstrap.css内部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM