使用基于url哈希值的jquery显示/隐藏?

时间:2013-10-02 09:14:04

标签: jquery bookmarks

我想出了以下脚本,根据网址中提供的#hashtag对页面执行操作。

function checkhash(){

x = window.location.hash.replace("#", "");
$('#results').html(x); //Just to show the results, Delete in your code
//Put your functions here....

if (x == 'all'){
    $(".one").add(".two").add(".three").hide();
    $(".one").show();
                // and so on... just an example
}

window.setTimeout(checkhash, 1);
}

checkhash();

有比上面更好的方法吗?我问,因为在它的当前形式中它将不断地反复检查一个新标签(我假设因为我不能像我想的那样使用fadeIn和fadeout方法)。我的用途是直接链接到/test.html#all以加载特定内容或以按钮的形式链接到其页面上的#all。两者都用于排序目的,例如全部按钮,蓝色,绿色,红色,页面可以直接转到链接#hash或使用#hash的页面上的按钮链接来显示/隐藏特定内容

它按原样运行(不能使用淡入淡出动画,但由于它不断运行,这是资源密集型的,如果可能的话我想避免这种情况。

0 个答案:

没有答案
相关问题