2016-08-25 51 views
0

我在軌道上使用紅寶石,並有一些前端的麻煩。我剛剛將JQuery砌體轉換成同位素。在砌體工程中,我的模型(稱爲件)正確對中和動畫。現在,使用同位素,動畫正在工作,但這一切都發生在一邊,而不是在頁面的中心。我怎樣才能解決這個問題?同位素不居中

更新:砌體代碼

這是與中心工作了,只能用磚石(在pieces.js)的代碼。我正在從這個軌道寶石加載同位素:https://github.com/kristianmandrup/masonry-rails。網站可以在https://www.metallicpalette.com/pieces查看。

$(function() { 
return $('#pieces').imagesLoaded(function() { 
    return $('#pieces').masonry({ 
    itemSelector: '.box', 
    isFitWidth: true 
    }); 
}); 
}); 

pieces.js

$(function() { 
    $('#pieces').imagesLoaded(function() { 
    var $grid = $('#pieces').isotope({ 
     itemSelector: '.box', 
     isFitWidth: true, 
     getSortData: { 
     title: function(itemElem) { 
      var title = $(itemElem).find('.title').text(); 
      return title; 
     }, 
     price: function(itemElem) { 
      var rawPrice = $(itemElem).find('.price').text(); 
      var price = parseFloat(rawPrice.replace(/[$\s]/g, '')); 
      return price; 
     } 
     } 
    }); 


    $('.filter-button-group').on('click', 'a', function() { 
     var filterValue = $(this).attr('data-filter'); 
     $grid.isotope({ filter: filterValue }); 
    }); 

    $('.sort-by-button-group').on('click', 'a', function() { 
     var sortByValue = $(this).data('sort-by'); 
     if (sortByValue) { 
     var ascending = true; 
     if ($(this).data('descending') === true) { 
      ascending = false; 
     } 
     $grid.isotope({ sortBy: sortByValue, sortAscending: ascending }); 
     } 
    }); 
    }); 
}); 

index.html.erb(主頁)

<div class="button-group center" role="group" aria-label="Filter and Sort"> 
    <!-- Sort stuff, this all works --> 
</div> 

<div id="pieces" class="transitions-enabled"> 
    <% @pieces.each do |piece| %> 
    <div class="box panel panel-default <%= piece.genre %>"> 
     <!-- piece content --> 
    </div> 
    <% end %> 
</div> 

pieces.scss

#pieces { 
    margin: 0 auto; 
} 

.box { 
    margin: 5px; 
    width: 214px; 
} 

.box img { 
    width: 100%; 
} 

.panel-default .panel-heading img { 
    width: 100%; 
} 


.isotope, 
.isotope .isotope-item { 
    /* change duration value to whatever you like */ 
    -webkit-transition-duration: 0.8s; 
    -moz-transition-duration: 0.8s; 
     -ms-transition-duration: 0.8s; 
     -o-transition-duration: 0.8s; 
      transition-duration: 0.8s; 
    } 

.isotope { 
    -webkit-transition-property: height, width; 
    -moz-transition-property: height, width; 
     -ms-transition-property: height, width; 
     -o-transition-property: height, width; 
      transition-property: height, width; 
} 

.isotope .isotope-item { 
    -webkit-transition-property: -webkit-transform, opacity; 
    -moz-transition-property: -moz-transform, opacity; 
     -ms-transition-property:  -ms-transform, opacity; 
     -o-transition-property:  -o-transform, opacity; 
      transition-property:   transform, opacity; 
} 

回答

1

當前版本同位素(v3)不需要.iso FYI。該選件isFitWidth現在是fitWidth和使用方法如下:

$('#pieces').imagesLoaded(function() { 
var $grid = $('#pieces').isotope({ 
    itemSelector: '.box', 
    masonry: { 
//columnWidth: 100, // You may need to set this value for your specific layout 
fitWidth: true 
} 
    getSortData: { 
    title: function(itemElem) { 
     var title = $(itemElem).find('.title').text(); 
     return title; 
    }, 
    price: function(itemElem) { 
     var rawPrice = $(itemElem).find('.price').text(); 
     var price = parseFloat(rawPrice.replace(/[$\s]/g, '')); 
     return price; 
    } 
    } 
}); 
+0

這並不爲我工作。你有另一個想法嗎?您可以在[此鏈接](https://www.metallicpalette.com/pieces/)上查看該網站。另外,我不認爲我正在使用同位素版本1,因爲如果沒有css,則轉換不起作用。 –

+0

您正在使用同位素的第一個版本。我沒有看到你的網頁上包含的任何代碼。至少使用v2可以使用isfitWidth。 – Macsupport

+0

你是什麼意思?「我沒有看到你的網頁上的任何代碼?」此外,它之前與砌體工作 - 我會更新我的問題,告訴你它是如何工作的。如果有幫助,我從這個欄目中加載同位素和磚石:https://github.com/kristianmandrup/masonry-rails –