2014-09-26 40 views
0

這是我一直在調整,以嘗試並獲得顏色框畫廊彈出的$(「#SV」)的點擊元素的JS代碼:創建colorbox畫廊彈出不同的div點擊?

$('#sv').click(function(event) { 
    event.preventDefault(); 

    $('.svItem').colorbox({ 
     width: '80%', 
     rel: 'gallery', 
     href: function() { 
      return $(this).data('href'); 
     }, 
     title: function() { 
      return $(this).text(); 
     } 
    }); 
}); 

,這裏是生成的HTML是什麼樣子我需要查詢:

<div class="col-md-4" id="sv"> 
    <div class="homeButton" style="background-image: url('/images/menu/btn_sv.png');"> 
     <div id="svItem0" class="svItem" rel="gallery" data-href="/images/sv/1.jpg" style="display:none"></div> 
     <div id="svItem1" class="svItem" rel="gallery" data-href="/images/sv/2.jpg" style="display:none"></div> 
     <div id="svItem2" class="svItem" rel="gallery" data-href="/images/sv/3.jpg" style="display:none"></div> 
     <div id="svItem3" class="svItem" rel="gallery" data-href="/images/sv/4.jpg" style="display:none"></div> 
     <h2 class="homeTitle shadow"> 
      Le saviez-vous? 
     </h2> 
    </div> 
</div> 

回答

0

得到它通過增加工作 「開:真」 有:

$('#sv').on('click', function(event) { 
    event.preventDefault(); 

    $('.svItem').colorbox({ 
     width: '80%', 
     open: true, 
     rel: 'gallery', 
     href: function() { 
      return $(this).data('href'); 
     } 
    }); 
});