$(document).ready(function(){
$('.fancygallery-panel').wrapAll('<div id="isotopeCont" />');
$('#filters a').click(function(){
var selector = $(this).attr('data-filter');
$('#isotopeCont').isotope({
filter: selector ,
animationEngine:'best-available'
});
return false;
});
})
我不是 jQuery 专家,但您不需要那里准备好文档吗?我使用列表项上的类以及活动状态以不同方式设置同位素。这是我的代码。
过滤器的 HTML
<div id="filter">
<ul>
<li><a href="" title="*">All</a></li>
<li><a href="" title="test1">1</a></li>
<li><a href="" title="test2">2</a></li>
<li><a href="" title="test3">3</a></li>
<li><a href="" title="test4">4</a></li>
<li><a href="" title="test5">5</a></li>
<li><a href="" title="test6">6</a></li>
</ul>
</div>
列表项画廊
<ul class="gallery simple" data-current="">
<li class="test5">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
<li class="test6">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
<li class="test5">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
<li class="test3">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
<li class="test1">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
<li class="test2">
<a href="largerimage.jpg" class="button-thumbs" data-fancybox-group="gallery" title=""><span class="hover"></span><img src="image.jpg"/></a>
</li>
jQuery
<script src="PATHTOYOURJSDIR/jquery.isotope.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var $container = $('ul.gallery');
var toFilter = '*';
$container.isotope({
filter: toFilter,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
$container.attr('data-current',toFilter);
checkActive();
$('#filter a').click(function(){
var title = $(this).attr('title');
var text = $(this).text();
if(text == "All"){
var selector = title;
}
else {
var selector = "." + title;
}
$container.attr('data-current',selector);
$container.isotope({
filter: selector,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
checkActive();
return false;
});
function checkActive(){
$('#filter a').each(function(){
$(this).removeClass("current");
var title = $(this).attr('title');
title = '.'+title;
if(title=='.*'){
title = '*';
}
var currentCat = $container.attr('data-current');
if(title==currentCat){
$(this).addClass("current");
}
});
}
var $container = $('ul.gallery')
// initialize Isotope
$container.isotope({
// options...
resizable: false, // disable normal resizing
// set columnWidth to a percentage of container width
masonry: { columnWidth: $container.width() / 4 }
});
// update columnWidth on window resize
$(window).smartresize(function(){
$container.isotope({
// update columnWidth to a percentage of container width
masonry: { columnWidth: $container.width() / 4 }
});
});
// trigger isotope again after images have loaded
$container.imagesLoaded( function(){
$(window).smartresize();
});
});
</script>
我正在做一个四跨响应式设计,你必须根据你的布局修改它并更改类和 ID。确保将html中调用的那些与jQuery中使用的结合起来。#filter ul.gallery等,并关闭所有标签,该系统不显示关闭</ul>