Isotope JS选项卡显示首次加载时的所有内容

时间:2017-11-13 08:59:40

标签: javascript jquery html css jquery-isotope

我使用Isotope JS来显示垂直标签中的内容。但是,每个选项卡都有不同的内容,当加载的初始时间显示所有选项卡中的内容一段时间。 1-2秒后就可以了。我们可以解决加载时间问题吗?实际上,在加载时我需要只显示第一个标签中的内容。



var first = $(".item:first")
$('#items').isotope({
  filter: first
});
// Filters out items
$('#filters a').click(function(e) {
  e.preventDefault()
  var selector = $(this).attr('data-filter');
  $('#items').isotope({
    filter: selector
  });
});

ul,
li {
  list-style: none;
  padding: 0;
  margin: 0;
}

a {
  text-decoration: none;
}

.isotop-tabs {
  border-right: 1px solid #aaa;
}

.isotop-tabs li {
  float: none;
  width: 100%;
}

.isotop-tabs li a {
  display: block;
  padding: 10px 0
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.4/isotope.pkgd.min.js"></script>

<div id="isotope">

  <div class="col-sm-3">
    <ul class="isotop-tabs" id="filters">
      <li><a href="#" data-filter=".one">Item one</a></li>
      <li><a href="#" data-filter=".two">Item two</a></li>
      <li><a href="#" data-filter=".three">Item three</a></li>
      <li><a href="#" data-filter=".four">Item four</a></li>
      <li><a href="#" data-filter=".five">Item five</a></li>
    </ul>
  </div>

  <div class="col-sm-9">
    <div id="items" class="item-list">
      <div class="item one">
        <img src="https://placeholdit.co//i/555x150" class="img-responsive">
        <h3>Heading One</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
      <div class="item two">
        <img src="https://placeholdit.co//i/555x150" class="img-responsive">
        <h3>Heading Two</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
      <div class="item three">
        <img src="https://placeholdit.co//i/555x150" class="img-responsive">
        <h3>Heading Three</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
      <div class="item four">
        <img src="https://placeholdit.co//i/555x150" class="img-responsive">
        <h3>Heading Four</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
      <div class="item five">
        <img src="https://placeholdit.co//i/555x150" class="img-responsive">
        <h3>Heading Five</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
          dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      </div>
    </div>
  </div>

</div>
&#13;
&#13;
&#13;

JSFiddle链接:https://jsfiddle.net/vishnuprasadps/c0kf8nyf/3/

1 个答案:

答案 0 :(得分:2)

我会

$('#items').isotope({
  // Options
}).addClass('is-show');

CSS

#items {
  display:none;
}
#items.is-show {
  display: block;
}

演示: https://jsfiddle.net/b7Lw18ny/