2015-02-06 96 views
0

我正在建立一个产品,我想打开和关闭点击,使用砌体。 我已经添加了onclick,但你可以看到 http://fi-testing.co.uk/zeffire-web/products.html 它的工作,但我有几个问题。 1)他们都打开onclick而不是相关的一个2)他们调整时不重新调整(他们重叠)3)我希望他们慢慢打开。砌体网格onclick

我已经尝试在.item函数中添加(仍然在代码中)slideDown(600, masonryUpdate);以对缓慢移动进行排序,并重新更新砌体,但那没有做任何事情。

这是全功能

$(document).ready(function(){ 
     $(".item").click(function(){ 
      $(".item").addClass("intro").slideDown(600, masonryUpdate); 
     }); 
    }); 

我已经使用这个http://masonry.desandro.com/appendix.html尝试,但我是一个新手,所以不能确定在哪里添加它,用“的onclick”部分对齐。

任何帮助将不胜感激?谢谢。

+1

我认为您正在寻找:'$(this).addClass(“intro”)。slideDown(600,masonryUpdate);' – Last1Here 2015-02-06 11:10:03

+0

yes!那种1)。谢谢。 – RachJenn 2015-02-06 11:12:02

+0

我希望其他人在当前人打开后关闭,这可能吗? – RachJenn 2015-02-06 11:15:49

回答

1

你必须这样做

$(document).ready(function(){ 
    $(".item").click(function(){ 
     var a= $(this), b = a.parent(); 
     b.find(".intro").each(function(index){ 
      if(a !== $(this)) { 
       // close this element since it's not the clicked one 
       // $(this).slideUp() or $(this).addClass('close') if you have a custom class for closing elements 
      } 
     }); 
     a.addClass("intro").slideDown(600, masonryUpdate); 
    }); 
}); 
+0

感谢票价,这与Last1Here的评论类似,但我希望其他人在当前票单打开后关闭,您能帮忙吗? – RachJenn 2015-02-06 11:14:18

+0

@RachJenn我刚刚编辑我的回应,以满足你想要的。试一试 – 2015-02-06 11:31:24

1

要解决问题1至处理您点击事件处理装有刚点击的元素),你会做什么,我评论

$(this).addClass("intro").slideDown(600, masonryUpdate);

为2)和3)你需要做类似

$(document).ready(function(){ 
    $(".item").click(function(){ 
     $(".intro").animate({"height": 500}, "fast").removeClass("intro"); // reset previous elements 

     $(this).addClass("intro").slideDown("slow", function() { msnry.layout(); }); // refresh layout 
    }); 
});