同位素砌体不能垂直堆叠可变高度的物品

时间:2017-04-10 09:24:29

标签: javascript jquery frontend jquery-isotope

有人可以解释我做错了什么,因为同位素插件的砌体布局对我来说不正常。为什么这些项目表现得像连续而不是堆叠砌体样式?

http://jsbin.com/vaposovuwo/edit?html,css,js

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

  <div class="grid">

    <div class="grid-item">
      <h3>Hello how are you fdgdfg dfgdf gdf gdjadfhg dfga fgaf gad </h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how are you</h3>
      <p>Lorem ipsum dsf sdfs df sdfsdfsdfs dfsdfsdf sdfs d fsdolor sit amet, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how are you</h3>
      <p>Lorem ipsum dolor sit adsfsd dsfsd met, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how asdf sdf sdf sdhgdtjhdghgdf fgd fre you</h3>
      <p>Lorem ipsum dolor sit amet, cons fdag adfag fda gadfgadf gadfg adf gadgad gadgad gad gagadf ectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how are you</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how are df gdf gdfhjtrhtrtrt hrhrt hrt rtyyou</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->

    <div class="grid-item">
      <h3>Hello how are you</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto facilis fuga asperiores, eos, nam numquam illum placeat, cumque minus nihil, repellendus. Blanditiis quia similique architecto, obcaecati inventore magnam cupiditate molestias.</p>
    </div> <!-- grid item -->
  </div>

  <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>

</body>
</html>

CSS

.grid-item {
  width: 300px;
  background-color: tomato;
  padding: 15px;
  margin: 15px;
  float: left;
}

JS

$(document).ready(function(){

  $('.grid').isotope({
    itemSelector: '.grid-item',

  });

});

1 个答案:

答案 0 :(得分:0)

最重要的是,你的jsbin没有加载jQuery,你也在尝试添加fit-columns.js两次同时添加isotope.js,但它不在脚本标记中。

这就是你所拥有的:

<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
//npmcdn.com/isotope-fit-columns@1/fit-columns.js

这是您需要的:

<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>
<script src="http://npmcdn.com/isotope-fit-columns@1/fit-columns.js"></script>