2016-03-02 37 views
0

我試圖讓我的投資組合的網站過濾庫,分配一個ID,就只顯示圖片帶有class = 「廊-1」(過濾器:」名爲.gallery-1' )使用<a href="http://miromannino.github.io/Justified-Gallery/" rel="nofollow">http://miromannino.github.io/Justified-Gallery/</a></p> <pre><code><button id="Gallery-1" >Gallery 1</button> </code></pre> <p>的想法是,當我點擊按鈕的畫廊1上單擊事件

$('button').click(function(){ 
    $('#mygallery').justifiedGallery({ 
     rowHeight : 200, 
     lastRow : 'justify', 
     margins : 30, 
     filter: '.Gallery-1' 
    }) 
}) 

是否有可能分配該被點擊 「過濾器」 按鈕的ID?這怎麼能做到?

回答

3

你可以得到點擊的元素的id

$('button').click(function(){ 
    var id = $(this).attr('id'); 
    // etc. 
}); 

然後,只需在前面加上.到它,你可以使用它作爲一個類過濾器:

$('button').click(function(){ 
    var id = $(this).attr('id'); 
    $('#mygallery').justifiedGallery({ 
     rowHeight : 200, 
     lastRow : 'justify', 
     margins : 30, 
     filter: '.' + id 
    }) 
}); 
相關問題