だから私はjquery同位体で遊んでいて、2つのオプションを1つのボタンに結合しようとしています
結果をフィルタリングするリンクのセットが1つあり、他のリンクのセットはレイアウトモードを変更します。フィルタリングだけでなく、レイアウトを変更するためのリンクをフィルタリングしたいと考えています。
私がデフォルトから変更しているレイアウトモードである背骨のドキュメントをここに示します。
1つはフィルターに設定され、もう1つはlayoutModeに設定されているため、問題はdata-option-keyにあると思います。異なる種類のdata-option-valueを持つ2つの異なるdata-option-keyを使用することは可能ですか?
スクリプトが続くhtmlは次のとおりです。
<section id="options">
<ul id="filters" class="option-set clearfix" data-option-key="filter">
<li><a href="#filter" data-option-value="*:not(.before)" class="selected">everything</a></li>
<li><a href="#filter" data-option-value=".modern">modern</a></li>
<li><a href="#filter" data-option-value=".traditional">traditional</a></li>
<li><a href="#filter" data-option-value=".commercial">commercial</a></li>
<li><a href="#filter" data-option-value=".automotive">automotive</a></li>
<li><a href="#filter" data-option-value=".bespoke">bespoke</a></li>
<li><a href="#filter" data-option-value=".before, .after">before <span style="font-size:10px;">&</span> after</a></li>
</ul>
<ul id="layouts" class="option-set clearfix" data-option-key="layoutMode">
<li><a href="#filter" data-option-value="masonry" class="selected">normal</a></li>
<li><a href="#filter" data-option-value="spineAlign">spine</a></li>
</ul>
</section> <!-- # O P T I O N S -->
<div id="result"></div>
<div id="container" class="clickable clearfix">
<div class="element portrait before">
<a href="img/gallery/large/beforeandafter/image1_before.jpg" rel="shadowbox[traditional]"><img src="img/gallery/thumbs/beforeandafter/image1_before.jpg" alt="chair" /></a>
</div>
<div class="element portrait after bespoke">
<a href="img/gallery/large/beforeandafter/image1_after.jpg" rel="shadowbox[traditional]"><img src="img/gallery/thumbs/beforeandafter/image1_after.jpg" alt="chair" /></a>
</div>
<div class="element portrait modern">
<a href="img/gallery/large/modern/image1.jpg" rel="shadowbox[traditional]"><img src="img/gallery/thumbs/modern/image1.jpg" alt="chair" /></a>
</div>
<div class="element landscape modern">
<a href="img/gallery/large/modern/image2.jpg" rel="shadowbox[traditional]"><img src="img/gallery/thumbs/modern/image2.jpg" alt="chair" /></a>
</div>
</div> <!-- # C O N T A I N E R -->
<script>
$(function(){
var $container = $('#container');
$container.isotope({
itemSelector : '.element',
filter: '*:not(.before)'
});
// custom layout mode spineAlign
$.Isotope.prototype._spineAlignReset = function() {
this.spineAlign = {
colA: 0,
colB: 1
};
};
$.Isotope.prototype._spineAlignLayout = function( $elems ) {
var instance = this,
props = this.spineAlign,
gutterWidth = Math.round( this.options.spineAlign && this.options.spineAlign.gutterWidth ) || 0,
centerX = Math.round(this.element.width() / 2);
$elems.each(function(){
var $this = $(this),
isColA = props.colB > props.colA,
x = isColA ?
centerX - ( $this.outerWidth(true) + gutterWidth / 2 ) : // left side
centerX + gutterWidth / 2, // right side
y = isColA ? props.colA : props.colB;
instance._pushPosition( $this, x, y );
props[( isColA ? 'colA' : 'colB' )] += $this.outerHeight(true);
});
};
$.Isotope.prototype._spineAlignGetContainerSize = function() {
var size = {};
size.height = this.spineAlign[( this.spineAlign.colB > this.spineAlign.colA ? 'colB' : 'colA' )];
return size;
};
$.Isotope.prototype._spineAlignResizeChanged = function() {
return true;
};
$(function(){
var $container = $('#container');
$container.isotope({
itemSelector : '.element',
layoutMode: 'spineAlign',
spineAlign: {
gutterWidth: 20
}
});
var $optionSets = $('#options .option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// make option object dynamically, i.e. { filter: '.my-filter-class' }
var options = {},
key = $optionSet.attr('data-option-key'),
value = $this.attr('data-option-value');
// parse 'false' as false boolean
value = value === 'false' ? false : value;
options[ key ] = value;
if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
// changes in layout modes need extra logic
changeLayoutMode( $this, options )
}
else {
// otherwise, apply new options
$container.isotope( options );
}
return false;
});
});
// filter buttons for shadowbox
$('#filters a').click(function(){
var selector = $(this).attr('data-option-value');
$container.isotope({ filter: selector });
// don't proceed if no Shadowbox yet
if ( !Shadowbox ) {
return false;
}
Shadowbox.clearCache();
$container.data('isotope').$filteredAtoms.each(function(){
Shadowbox.addCache( $(this).find('a[rel^="shadowbox"]')[0] );
});
return false;
});
});
</script>
正しい方向への微調整に感謝します
ありがとう
編集:リンクがクリックされたときにjqueryを使用してコンテナのサイズを変更するという別のアプローチも試しています。しかし、これには独自の問題があります。サイズを変更することはできますが、フィルターが変更された場合、画像はコンテナー内に保持されません。代わりに、もう一度クリックするまで、新しく形成された小さなコンテナーの外側に残され、収まるように内側に再配置されます。とても近い!
私がこれをしようとしていたコード:
// change the width of the container depending on the filter
if ( $this.hasClass('thin') ) {
$container
.css({'width': '636px','margin-left': '132px'})
.isotope('reLayout');
}
if ( $this.hasClass('thick') ) {
$container
.css({'width': '960px','margin-left': '0'})
.isotope('reLayout');
}