我正在使用同位素,这是 jsfiddle:http: //jsfiddle.net/desandro/DA3wF/
或者,或者,我设置了一个演示:http: //nerdi.net/isotope-test.html
有一个选项filter: selector
我怎么能通过一个过滤器,例如:index.html#green
在页面加载时,会过滤到.green
类?这可能吗?
我正在使用同位素,这是 jsfiddle:http: //jsfiddle.net/desandro/DA3wF/
或者,或者,我设置了一个演示:http: //nerdi.net/isotope-test.html
有一个选项filter: selector
我怎么能通过一个过滤器,例如:index.html#green
在页面加载时,会过滤到.green
类?这可能吗?
filter: (window.location.hash != '') ? '.' + window.location.hash.replace('#', '') : 'default'
这是一个if/then
检查当前哈希是否为空字符串的语句。如果是filter
则将设置为default
否则将设置为该window.location.hash
值(减去#
)。
像这样的 URLindex.html
将filter
被设置为default
,像这样的 URLindex.html#my-selector
将filter
被设置为.my-selector
。
您的代码不起作用的原因实际上与我的代码没有任何关系,但这是我在您的网站上测试的代码的更新版本:
$filterLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return;
}
$filterLinks.filter('.selected').removeClass('selected');
$this.addClass('selected');
// get selector from data-filter attribute
var selector = $this.data('option-value');
$container'.isotope({
filter: selector
});
});
filter: window.location.hash.replace('#', '.')
location.hash 将返回“#green”,我们只需将其替换为一个点即可获得“.green”。
jsfiddle示例如何根据哈希更改所选链接。