2016-06-13 47 views
6

在單個頁面中添加Bootstrap Carousel SliderLightbox Gallery似乎非常具有挑戰性,而且沒有重大問題。莫代爾燈箱畫廊和旋轉木馬滑塊不兼容?

問題:當在燈箱圖片庫點擊它打開了圖片庫,並在同一時間旋轉木馬滑塊圖像得到由畫廊圖像劫持。罪魁禍首似乎兩個類:.itemIMG,或.inner傳送帶

是否有可能沒有任何問題都態lighbox和傳送帶滑塊添加到一個頁面?

要重現該問題:點擊圖片庫,該模式會彈出,關閉窗口,現在的旋轉木馬滑塊已被畫廊圖像所取代。 http://jsfiddle.net/2aasoyej/

HTML:

<div class="container"> 
    <div class="row"> 
    <h1>Bootstrap 3 lightbox hidden gallery using modal</h1> 
     <hr> 

    <div class="row"> 

       <div class="col-12 col-md-4 col-sm-6"> 
        <a title="Image 1" href="#"> 
         <img class="thumbnail img-responsive" id="image-1" src="http://dummyimage.com/600x350/ccc/969696&amp;text=0xD10x810xD00xB50xD10x800xD10x8B0xD00xB9"> 
        </a> 
       </div> 

       <div class="col-12 col-md-4 col-sm-6"> 
        <a title="Image 2" href="#"> 
         <img class="thumbnail img-responsive" id="image-2" src="http://dummyimage.com/600x350/2255EE/969696&amp;text=0xD10x810xD00xB80xD00xBD0xD00xB80xD00xB9"> 
        </a> 

       </div> 
       <div class="col-12 col-md-4 col-sm-6"> 
        <a title="Image 3" href="#"> 
         <img class="thumbnail img-responsive" id="image-3" src="http://dummyimage.com/600x350/449955/FFF&amp;text=0xD00xB70xD00xB50xD00xBB0xD00xB50xD00xBD0xD10x8B0xD00xB9"> 
        </a> 
       </div> 
    </div> 

    <hr> 

    </div> 
</div> 

    <div class="hidden" id="img-repo"> 

     <!-- #image-1 --> 
     <div class="item" id="image-1"> 
      <img class="thumbnail img-responsive" title="Image 11" src="http://dummyimage.com/600x350/ccc/969696"> 
     </div> 
     <div class="item" id="image-1"> 
      <img class="thumbnail img-responsive" title="Image 12" src="http://dummyimage.com/600x600/ccc/969696"> 
     </div> 
     <div class="item" id="image-1"> 
      <img class="thumbnail img-responsive" title="Image 13" src="http://dummyimage.com/300x300/ccc/969696"> 
     </div> 

     <!-- #image-2 --> 
     <div class="item" id="image-2"> 
      <img class="thumbnail img-responsive" title="Image 21" src="http://dummyimage.com/600x350/2255EE/969696"> 
     </div> 
     <div class="item" id="image-2"> 
      <img class="thumbnail img-responsive" title="Image 21" src="http://dummyimage.com/600x600/2255EE/969696"> 
     </div> 
     <div class="item" id="image-2"> 
      <img class="thumbnail img-responsive" title="Image 23" src="http://dummyimage.com/300x300/2255EE/969696"> 
     </div> 

     <!-- #image-3--> 
     <div class="item" id="image-3"> 
      <img class="thumbnail img-responsive" title="Image 31" src="http://dummyimage.com/600x350/449955/FFF"> 
     </div> 
     <div class="item" id="image-3"> 
      <img class="thumbnail img-responsive" title="Image 32" src="http://dummyimage.com/600x600/449955/FFF"> 
     </div> 
     <div class="item" id="image-3"> 
      <img class="thumbnail img-responsive" title="Image 33" src="http://dummyimage.com/300x300/449955/FFF"> 
     </div>   

    </div> 

<div class="modal" id="modal-gallery" role="dialog"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <button class="close" type="button" data-dismiss="modal">×</button> 
      <h3 class="modal-title"></h3> 
     </div> 
     <div class="modal-body"> 
      <div id="modal-carousel" class="carousel"> 

      <div class="carousel-inner">   
      </div> 

      <a class="carousel-control left" href="#modal-carousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a> 
      <a class="carousel-control right" href="#modal-carousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a> 

      </div> 
     </div> 
     <div class="modal-footer"> 
      <button class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 
    </div> 
</div> 





     <!-- Header Carousel --> 
    <header id="myCarousel" class="carousel slide"> 
     <!-- Indicators --> 
     <ol class="carousel-indicators"> 
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li> 
      <li data-target="#myCarousel" data-slide-to="1"></li> 
      <li data-target="#myCarousel" data-slide-to="2"></li> 
     </ol> 

     <!-- Wrapper for slides --> 
     <div class="carousel-inner"> 
      <div class="item active"> 

       <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide One');">  
       <center> 
       <div class="carousel-title"> 
        <h1>Certified General Contractor</h1> 
       </div> 

       </center> 
       </div> 

       <div class="carousel-caption"> 

        <h2>For all your South Florida construction needs</h2> 
       </div> 
      </div> 
      <div class="item"> 
       <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide Two');"> 
         <center> 
       <div class="carousel-title"> 
        <h1>Commercial Contruction</h1> 
       </div> 

       </center> 
        </div> 
       <div class="carousel-caption"> 
        <h2>Build with a company you can trust</h2> 
       </div> 
      </div> 
      <div class="item"> 
       <div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide Three');"> 

        <center> 
       <div class="carousel-title"> 
        <h1>Home Renovation</h1> 
       </div> 

       </center> 
      </div> 
       <div class="carousel-caption"> 
        <h2>Remodel your home with the best in the field</h2> 
       </div> 
      </div> 
     </div> 

     <!-- Controls --> 
     <a class="left carousel-control" href="#myCarousel" data-slide="prev"> 
      <span class="icon-prev" style="font-size:70px;"></span> 
     </a> 
     <a class="right carousel-control" href="#myCarousel" data-slide="next"> 
      <span class="icon-next" style="font-size:70px;"></span> 
     </a> 

JS:

var $item = $('.carousel .item'); 
var $wHeight = $(window).height(); 
$item.eq(0).addClass('active'); 
$item.height($wHeight); 
$item.addClass('full-screen'); 

$('.carousel img').each(function() { 
    var $src = $(this).attr('src'); 
    var $color = $(this).attr('data-color'); 
    $(this).parent().css({ 
    'background-image' : 'url(' + $src + ')', 
    'background-color' : $color 
    }); 
    $(this).remove(); 
}); 

$(window).on('resize', function(){ 
    $wHeight = $(window).height(); 
    $item.height($wHeight); 
}); 

$('.carousel').carousel({ 
    interval: 6000, 
    pause: "false" 
}); 
+0

JavaScript代碼的有趣部分在這裏不存在,但可以在小提琴中找到 –

回答

9

$( 「行.thumbnail。」)點擊(函數()您要查詢。 $('。carousel-inner')這實際上匹配兩個轉盤'.carousel-inner

$(".row .thumbnail").click(function(){ 
    var content = $(".carousel-inner"); 

..和然後調用content.empty()content.append(倉庫複製)。當然,這對兩個輪播也都有影響。

你需要更精確的位置:

$(".row .thumbnail").click(function(){ 
    var content = $("#modal-carousel .carousel-inner"); 

下面是更新小提琴:http://jsfiddle.net/2aasoyej/1/

Udated小提琴,妥善禁用的模式轉盤的時間間隔,如在下面的評論指出:http://jsfiddle.net/2aasoyej/4/

+0

感謝您的答案,但是您剛剛創建了另一個問題。看看你提供的更新的小提琴,當你點擊圖像時,它應該在圖庫模式下彈出,但相反它彈出在傳送帶模式。圖像庫現在變成幻燈片。 – ChosenJuan

+0

您的原創小提琴在這裏完全一樣,這是可以預料的,因爲您只是將「畫廊」傳送帶包裹在模態窗口中。你如何期待它看起來像完全一樣? –

+0

旋轉木馬應自動播放圖片幻燈片,但圖片庫應打開一個模式圖片,您可以滾動瀏覽,但不會自動播放(即不是像傳送帶一樣的幻燈片) – ChosenJuan