2012-01-10 87 views
0

我想了解如何使用Combination filtersJquery BBQ Hash HistoryjQuery同位素組合過濾器與燒烤哈希歷史混合 - 需要幫助瞭解如何

我想要做的是讓用戶按標識,標識或品牌過濾。如果用戶點擊徽標,我希望他們可以通過「非營利,教育,零售」等方式進行子過濾。我知道組合過濾器在沒有實施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; 
    }); 

回答

4

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

}); 
+1

解決 - 從創造者本人!非常感謝Desandro先生。它完美的作品。無論如何,我的確看上去很高,但是我們必須忽視這一點。再次感謝。 – Chongo 2012-01-11 15:29:16

+1

它看起來像你的例子打破了後退和前進按鈕的功能。這是隻有燒烤會幫助嗎? – Chongo 2012-01-16 22:46:12

+0

感謝這裏的解決方案,但鏈接已損壞。它在您的支持頁面的任何地方仍然可用? – 2013-10-25 12:05:33