2011-11-01 67 views
7

标题几乎说了一切,我看了一下砌体的图像插件,但我没有运气,我想知道有没有人可以帮忙?砌体图像重叠问题

该脚本做了很多事情,它有过滤器位,动画,显示/隐藏,ajax来获取内容等。如果有人可以调查为什么它重叠,我可以解决我会很高兴它基于以下代码:

jQuery(function(){ 
    jQuery('#container').masonry({ 
    itemSelector: '.box', 
    animate: true 
    }); 
    }); 



    (function ($) { 
// Get all menu items with IDs starting with "filter-" and loop over them 
$(".menu li[id|=filter]").each(function() { 
    // Get the ID add extract the page class name from it (remove "filter-"  from it) 
    var type = $(this).attr("id").replace("filter-", ""); 
    // Get the items in the "webbies" list with that class name 
    var items = $("#container div[class~=" + type + "]"); 
    // Don't do anything if there aren't any 
    if (items.length == 0) return; 
    // Get a list of the other items in the list 
    var others = $("#container>div:not([class~=" + type + "])"); 
    // Add a click event to the menu item 
    $("a", this).click(function (e) { 
     // Stop the link 
     e.preventDefault(); 
     // Close open item 
     if (openItem) { 
      close(openItem); 
     } 
     items.removeClass("inactive").animate({opacity: 1}); 
     others.addClass("inactive").animate({opacity: 0.2}); 
    }); 
}); 

$(".reset-filter a").click(function (e) { 
    e.preventDefault(); 
    if (openItem) close(openItem); 
    $("div.box.inactive").removeClass("inactive").animate({opacity: 1}); 
}); 

var openItem; 

// Opens an item 
var open = function (item) { 
    // Close open item 
    if (openItem) close(openItem); 
    item.addClass("loading"); 
    $("img", item).first().hide(); 
    item.width(340); 
    item.height(600); 
    if (!item.data('loaded')) { 
     $("div.fader", item).load($("a", item).first().attr("href") + " #content", function() { 
      stButtons.locateElements(); 
      stButtons.makeButtons(); 
      stWidget.init(); 
      $("#container").masonry('reloadItems', function() { 
       $("div.fader", item).animate({opacity: 1}, function() { 
        item.removeClass("loading"); 
        $('<a href="#" class="close">Close</a>"').appendTo(this).click(function (e) { 
         e.preventDefault(); 
         close(item); 
         $(document).scrollTo( $("#navigation-block"), 600, {offset:-50}); 
        }); 
        $("div.info", item).fadeIn("slow", function() { 
         $(document).scrollTo($(".info"), 600, {offset:80}); 
        }); 
       }); 
      }); 
      item.data('loaded', true); 
     }); 
    } else { 
     item.removeClass("loading"); 
     $("#container").masonry('reloadItems', function() { 
      $("div.fader", item).animate({opacity: 1}, function() { 
       $("div.info", item).fadeIn("slow", function() { 
        $(document).scrollTo($(".info"), 600,     {offset:80}); 
       }); 
      }); 
     }); 
    } 

    // Set open item 
    openItem = item; 

}; 

// Closes an item 
var close = function (item) { 
    $("div.fader", item).animate({opacity: 0}); 
    $("div.info", item).hide(); 
    item.animate({width: 150, height: 100}, function() { 
     $("img", item).first().fadeIn("slow"); 
     $("#container").masonry('reloadItems'); 
    }); 

    // Reset open item 
    openItem = null; 
}; 

$("#container div.box").each(function() { 
    var item = $(this); 
    item.data('loaded', false); 
    $("div.fader", item).css("opacity", 0); 
    $("a.close", item).click(function (e) { 
     e.preventDefault(); 
     close(item); 
     $(document).scrollTo($("#navigation-block"), 600, {offset:-50}); 
    }); 
    $("a.showMe", item).click(function (e) { 
     e.preventDefault(); 

     if (item.hasClass("inactive")) return; 
     open(item); 
    }); 
}); 
    })(jQuery); 
    </script> 
+0

也许是与此http://wordpress.stackexchange.com/questions/60635/images-overlapping-in-google-chrome/60636#60636 – Diana

回答

9
jQuery(function(){ 
    var $container = $('#container'); 
    $container.imagesLoaded(function() { 
     itemSelector: '.box', 
     animate: true 
    }); 
    }); 

来源:jQuery Masonry Images

+0

这是不正确的 - 一个函数不是一个js对象。 –

+0

更好地说,因为我以前的观点不一定是正确的,所以函数不能这样使用。 –

10

我遇到了同样的问题,我开发了2种方法来解决它。首先在添加onclick-image后重新加载容器。

1. container.masonry('reload'); 

其次,可能更重要的是,动态地修正周边div的高度来匹配图像的高度:

2. // bricks correct height 
    var brick = $("#marker #container .brick"); 
    brick.each(function() { 
      var content = $(this).find(">div"); 
      var img = $(this).find("img"); 
      content.css({ 
      height: img.attr("height") 
      }); 
     }); 

所以我的砖看起来像这样:

<div style="height: 284px; position: static; top: -133px;" class="test"> 
     <a class="arrow" href="#" target="_self"><img class="img" src="test.jpg" width="374" height="284"></a> 
    </div> 

编辑:在你的代码中你有同样的问题,风格没有高度。

<div style="position: absolute; left: 330px; top: 280px;" class="box item 3d"> 

在我看来,你也有宽度问题。我认为你需要使用一个较小的宽度列。一个好的价值将是小图像和一些边界的宽度。

+0

毫米,使感觉和它是有希望的,谢谢。将有尝试并回复 –

+0

如果您已经定义了图像尺寸,这只是一个有效的解决方案。如果是这样,盒模型将负责任何重叠。明确设置高度/宽度是多余的。 – desandro