【问题标题】:jQuery Isotope Combination Filters mixed with BBQ Hash History - Need help understanding how tojQuery 同位素组合过滤器与 BBQ 哈希历史混合 - 需要帮助了解如何
【发布时间】:2012-01-11 22:16:29
【问题描述】:

我正在尝试了解如何将Combination filtersJquery BBQ Hash History 一起使用。

我想做的是让用户按徽标、身份或品牌过滤。如果用户单击徽标,我希望他们能够按“非营利、教育、零售”等进行子过滤。我知道组合过滤器可以在没有实现 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;
  });

【问题讨论】:

    标签: jquery jquery-isotope jquery-bbq


    【解决方案1】:

    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
        }
      });
    
    });
    

    【讨论】:

    • 已解决 - 来自创作者本人!非常感谢德桑德罗先生。它完美地工作。对于任何一个例子,我真的看起来很高和很低,但必须忽略这个。再次感谢。
    • 您的示例似乎破坏了后退和前进按钮的功能。这是只有烧烤才能解决的问题吗?
    • 感谢您的解决方案,但链接已损坏。它在您的支持页面上的任何地方仍然可用吗?
    猜你喜欢
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    相关资源
    最近更新 更多