1

プロジェクトでjQuery Isotopeを使用しています。

別のページの a href リンクからフィルター値を渡すことはできますか? そのため、アイソトープのあるページにアクセスすると、a href に基づいてレイアウトがフィルター処理されます。

4

1 に答える 1

1

はい。jQuery BBQを利用する Isotopeのハッシュ履歴アドインを使用できます。

この例は、Isotope ドキュメントのハッシュ履歴ページのソースからのコピペです。

$(window).bind( 'hashchange', function( event ){
    // get options object from hash
    var hashOptions = window.location.hash ? $.deparam.fragment( window.location.hash, true ) : {},
        // do not animate first call
        aniEngine = hashChanged ? 'best-available' : 'none',
        // apply defaults where no option was specified
        options = $.extend( {}, defaultOptions, hashOptions, { animationEngine: aniEngine } );
// apply options from hash
$container.isotope( options );
// save options
isotopeOptions = hashOptions;

// if option link was not clicked
// then we'll need to update selected links
if ( !isOptionLinkClicked ) {
  // iterate over options
  var hrefObj, hrefValue, $selectedLink;
  for ( var key in options ) {
    hrefObj = {};
    hrefObj[ key ] = options[ key ];
    // convert object into parameter string
    // i.e. { filter: '.inner-transition' } -> 'filter=.inner-transition'
    hrefValue = $.param( hrefObj );
    // get matching link
    $selectedLink = $optionSets.find('a[href="#' + hrefValue + '"]');
    changeSelectedLink( $selectedLink );
  }
}

isOptionLinkClicked = false;
hashChanged = true;
})

    // trigger hashchange to capture any hash data on init
    .trigger('hashchange');

});
于 2012-04-18T01:45:46.200 に答える