簡體   English   中英

包含燒烤哈希歷史記錄的jQuery同位素組合過濾器-需要幫助以了解如何

[英]jQuery Isotope Combination Filters mixed with BBQ Hash History - Need help understanding how to

我試圖了解如何將組合篩選器Jquery BBQ哈希歷史記錄一起使用

我想做的是讓用戶按徽標,身份或品牌進行過濾。 如果用戶單擊徽標,那么我希望他們能夠通過“非營利,教育,零售”等子過濾器。我知道組合過濾器可以很好地實現jquery BBQ代碼,但我想兩者都做。

    $optionSets.find('.filter-main a').click(function(){
    var $this = $(this);
    // don't proceed if already selected
    if ( $this.hasClass('selected') ) {
      return;
    }
    changeSelectedLink( $this );
        // get href attr, remove leading #
    var href = $this.attr('href').replace( /^#/, '' ),
        // convert href into object
        // i.e. 'filter=.inner-transition' -> { filter: '.inner-transition' }
        option = $.deparam( href, true );
    // apply new option to previous
    $.extend( isotopeOptions, option );
    // set hash, triggers hashchange on window
    $.bbq.pushState( isotopeOptions );
    isOptionLinkClicked = true;
    return false;
  });

參見http://support.metafizzy.co/2011/isotope-combo-filters-hash-links.html

$(function(){
  var $container = $('#container'),
      filters = {},
      // get filter from hash, remove leading '#'
      filterSelector = window.location.hash.slice(1);

  $('#filters a').click(function(){
    // store filter value in object
    // i.e. filters.color = 'red'
    var $this = $(this),
        name = $this.attr('data-filter-name'),
        value = $this.attr('data-filter-value'),
        isoFilters = [],
        filterName, prop;

    filters[ name ] = value;

    for ( prop in filters ) {
      isoFilters.push( filters[ prop ] );
    }

    var filterSelector = isoFilters.join('');

    // trigger isotope if its ready
    if ( $container.data('isotope') ) {
      $container.isotope({ filter: filterSelector });
    }

    window.location.hash = filterSelector;

    // toggle highlight
    $this.parents('ul').find('.selected').removeClass('selected');
    $this.parent().addClass('selected');

    return false;

  });


  // if there was a filter, trigger a click on the 
  // corresponding option
  if ( filterSelector ) {
    var selectorClasses = filterSelector.split('.').slice(1);
    $.each( selectorClasses, function( i, selectorClass ) {
      $('#filters a[data-filter-value=".' + selectorClass + '"]').click();
    });
  }

  $('#container').isotope({
    itemSelector: '.item',
    filter: filterSelector,
    masonry: {
      columnWidth: 80
    }
  });

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM