我可以从不同的页面传递过滤值吗?

时间:2012-04-18 01:41:07

标签: javascript jquery jquery-isotope

我在项目中使用jQuery Isotope

我可以从其他页面上的href链接向其传递过滤器值吗?因此,当我使用同位素登陆页面时,它会根据a href过滤布局。

1 个答案:

答案 0 :(得分:1)

是。您可以使用hash history addin for Isotope,它使用jQuery BBQ

此示例只是来自Isotope文档上哈希历史记录页面源的copypasta。

$(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');

});