2014-04-01 35 views
0

我正在使用像http://masonry.desandro.com/methods.html#layout這樣的佈局,並想知道是否有辦法在他們的時間只有一個項目處於活動狀態。因此,當您展開一個新項目時,您當前打開的項目會恢復爲原始形式(刪除class =「is_expanded」)。從來就很新的編程和鴕鳥政策真的知道去哪裏統計看,試圖配置How do I remove class from previous selection when clicking additional item?,但沒有運氣砌體,刪除「is_expanded」類,當新項目被點擊

回答

0
classie.toggle(event.target, 'gigante'); 

這是一部分,做魔術 - 它增加了一類「希甘特」,這然後使得4×4(或其他)

如果你想只能有一個時間,然後

eventie.bind(container, 'click', function(event) { 
// don't proceed if item was not clicked on 
if (!classie.has(event.target, 'item')) { 
return; 
} 

// change size of item via class 
$('.item').removeClass('gigante'); // add this line 
classie.toggle(event.target, 'gigante'); 
// trigger layout 
msnry.layout(); 
}); 

我加入做線路是從項目中刪除所有「希甘特」級擴大然後切換將再次將該類添加到該項目。

$('.item')只是每個項目都有的類。

這個答案假設只有擴展項目纔會被稱爲'gigante'。

+0

謝謝你,工作就像一個魅力,而且我想我知道如何在將來需要時添加類似的功能。 – Karl

+0

$(函數(){ 變量$容器= $(」。磚石 ')砌體({ columnWidth時:130, 排水溝:5 }); $ container.on( '點擊','。。 ('。item')。removeClass('is-expanded'); //添加這一行 $(this).parent('。item')。toggleClass('is 「; $ container.masonry(); }); }); – Karl