2012-07-15 46 views
1

我正在滾動我自己的無DB數據庫(live here),並且希望使用Masonry來製作沒有大量空白空間的縮略圖(儘管這更像是「灰色空間」在我的網站上)。砌體平原OL不工作

我相信我正確地實現它:

var $container=$('#main'); 
     $container.imagesLoaded(function(){ 
      $container.masonry({ 
       itemSelector : '.box', 
       columnWidth: 200 
      }); 
     }); 

也許一個問題是,我使用的是另一段代碼圓縮略圖的邊緣:

$("img.rounded_corners").each(function() { 
      $(this).wrap('<div class="box rounded_corners" />'); 
      var imgSrc = $(this).attr("src"); 
      var imgHeight = $(this).height(); 
      var imgWidth = $(this).width(); 
      $(this).parent() 
       .css("background-image", "url(" + imgSrc + ")") 
       .css("background-repeat","no-repeat") 
       .css("background-color","#fff") 
       .css("height", imgHeight + "px") 
       .css("width", imgWidth + "px"); 
      $(this).remove(); 
     }); 

這基本上用div替換圖像,我已經添加了相應的「框」類。

儘管如此,頁面上的佈局仍然保持不變。出了什麼問題?

謝謝!

+0

如果您刪除第二個JS代碼,砌體工程的結束? – Andre 2012-07-15 06:41:18

+0

我檢查了控制檯打開的頁面,砌體插件拋出錯誤 – Andre 2012-07-15 06:50:44

+0

噢,好的......錯誤是什麼? – NaOH 2012-07-15 06:56:43

回答

2

現在懂了......我不知道怎麼我以前沒有

看到了這一點這不是砌築/一個錯誤的jQuery版本

腳本這是所有包裝中的圖像.box div在圖像加載到文檔之前運行。所以,沒有選擇任何東西,並且當砌體腳本運行時,沒有類別爲box的元素。

因此,將最後一個腳本到身體

<script type="text/javascript"> 
      Shadowbox.init(); 
      $("img.rounded_corners").each(function() { 
       $(this).wrap('<div class="box rounded_corners" />'); 
       var imgSrc = $(this).attr("src"); 
       var imgHeight = $(this).height(); 
       var imgWidth = $(this).width(); 
       $(this).parent() 
        .css("background-image", "url(" + imgSrc + ")") 
        .css("background-repeat","no-repeat") 
        .css("background-color","#fff") 
        .css("height", imgHeight + "px") 
        .css("width", imgWidth + "px"); 
       $(this).remove(); 
      }); 
      var $container=$('#main'); 
      $container.imagesLoaded(function(){ 
       $container.masonry({ 
        itemSelector : '.box', 
        columnWidth: 200 
       }); 
      }); 
      </script> 
</body> <!-- just above the end of the body. In fact, this is said to be a good practice: leave the external js files in the head, and inline js at the end --> 
+0

啊!好吧,現在看起來似乎正在工作,除了它所做的一切是將所有內容塞進一個單獨的列中,而不是像它應該放置的東西......任何想法爲什麼可能會發生? – NaOH 2012-07-15 17:05:27

+0

Aaaand現在正在加載圖像,接着刷新或兩次。我看到他們正在加載源代碼,但不是在屏幕上......因此,如果將「圓角」功能移動到頁面底部,似乎存在問題。 – NaOH 2012-07-15 17:17:28

+0

它似乎在當地工作。 – Andre 2012-07-15 17:27:36