jQuery Isoptope设置通过URL的默认排序过滤器 [英] jQuery Isoptope Setting Default Sorting Filter Through URL
问题描述
我想知道这个小提琴是什么问题: http://jsfiddle.net/GwBa8/150/
I am wondering what is the issue with this fiddle: http://jsfiddle.net/GwBa8/150/
我想更改默认情况下使用其他链接加载的类别,而不必向我的网站添加额外的页面.最后的工作状态是 http://jsfiddle.net/GwBa8/128/.唯一的区别是将以下代码添加到jQuery的开头.
I want to change which category loads by default using different links without having to add extra pages to my site. The last working state is this fiddle http://jsfiddle.net/GwBa8/128/. The only difference is the following code added to the start of the jQuery.
//e.g. website.com/index/filter/games
var $criteria = '*';
var str = window.location.pathname;
//games
if (str.substring(str.lastIndexOf('#'))) {
var $criteria='.'+str.substring(str.lastIndexOf('#'));
} else {
var $criteria = '*';
}
为什么这段代码会使它停止工作?
Why does this code stop it working?
我想使用www.website/index#games之类的东西来默认加载游戏.
I would like to have something like www.website/index#games to load games by default.
谢谢!
推荐答案
基于@nchaud注释...
Based on @nchaud comment...
$(window).load(function(){
//e.g. website.com/index/filter#games
var str = document.URL;
//games
if ((str.lastIndexOf('#'))!== -1) {
var $criteria=str.substring(str.lastIndexOf('#'));
} else {
var $criteria = '#all';
}
这会将变量$ criteria设置为导航中类别链接的匹配ID.
This sets the variable $criteria to the matching id of the link for the category in the navigation.
var $container = $('.creations-container');
$container.isotope({
filter: '*',
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
$('.creations-filter a').click(function(){
$('.creations-filter .current').removeClass('current');
$(this).addClass('current');
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
return false;
});
$($criteria).trigger("click");
这会点击网址中具有ID的元素
this clicks on the element with the id in the url
这篇关于jQuery Isoptope设置通过URL的默认排序过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!