【发布时间】:2010-08-09 16:03:06
【问题描述】:
我有一个硬编码的 li 菜单,它使用 filterable.js 根据哈希标签过滤项目列表。
如果项目被选中,我可以专注于工作,但是,我希望在页面加载时选择所有标签。我将“current”类添加到“all”菜单项,但这不起作用。
见:http://thinquetanque.com/portfolio
filterable.js 的代码:
/*
* Copyright (C) 2009 Joel Sutherland.
* Liscenced under the MIT liscense
*/
(function($) {
$.fn.filterable = function(settings) {
settings = $.extend({
useHash: true,
animationSpeed: 5000,
show: { width: 'show', opacity: 'show' },
hide: { width: 'hide', opacity: 'hide' },
useTags: true,
tagSelector: '#portfolio-filter a',
selectedTagClass: 'current',
allTag: 'all'
}, settings);
return $(this).each(function(){
/* FILTER: select a tag and filter */
$(this).bind("filter", function( e, tagToShow ){
if(settings.useTags){
$(settings.tagSelector).removeClass(settings.selectedTagClass);
$(settings.tagSelector + '[href=' + tagToShow + ']').addClass(settings.selectedTagClass);
}
$(this).trigger("filterportfolio", [ tagToShow.substr(1) ]);
});
/* FILTERPORTFOLIO: pass in a class to show, all others will be hidden */
$(this).bind("filterportfolio", function( e, classToShow ){
if(classToShow == settings.allTag){
$(this).trigger("show");
}else{
$(this).trigger("show", [ '.' + classToShow ] );
$(this).trigger("hide", [ ':not(.' + classToShow + ')' ] );
}
if(settings.useHash){
location.hash = '#' + classToShow;
}
});
/* SHOW: show a single class*/
$(this).bind("show", function( e, selectorToShow ){
$(this).children(selectorToShow).fadeIn('slow');
});
/* SHOW: hide a single class*/
$(this).bind("hide", function( e, selectorToHide ){
$(this).children(selectorToHide).fadeOut('slow');
});
/* ============ Check URL Hash ====================*/
if(settings.useHash){
if(location.hash != '')
$(this).trigger("filter", [ location.hash ]);
else
$(this).trigger("filter", [ '#' + settings.allTag ]);
}
/* ============ Setup Tags ====================*/
if(settings.useTags){
$(settings.tagSelector).click(function(){
$('#portfolio-list').trigger("filter", [ $(this).attr('href') ]);
$(settings.tagSelector).removeClass('current');
$(this).addClass('current');
});
}
});
}
})(jQuery);
$(document).ready(function(){
$('#portfolio-list').filterable();
});
这是在我的投资组合项目列表中添加和删除“当前”类。我确定一定有jquery函数来加载一个类,但是我没有找到。
任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: jquery class menu filter focus