0

我对javascript知之甚少,所以这对我来说真的很难:(

我正在使用Tympanus手风琴,但不知道如何链接到某个项目并显示它已打开(使用锚链接,例如 page/#3442)

这款手风琴非常简单易用,但没有更多示例,或者这不可能?!

我在链接中添加了 ID,所以我希望我可以访问http://site.com/page#123并查看打开的项目,有一个选项可以设置默认打开的项目,open = "the index"我想我需要一个函数来从提交的 URL 中获取 ID 并将其动态传递给手风琴参数但是无法弄清楚如何:(:

$.Accordion.defaults        = {

    open            : -1, //index of opened item, -1 is none, 0 is the 1st item etc
    oneOpenedItem           : false,
    speed           : 600,
    easing          : 'easeInOutExpo',
    scrollSpeed     : 900,
    scrollEasing            : 'easeInOutExpo'
};

谢谢你的帮助。

在 Jsfiddle 中设置:http: //jsfiddle.net/uwn4P/

4

2 回答 2

1

window.location.hash will get you the hash from the address bar if that's what you are looking for.

So you can easily store it in a variable let's say like this:

var item;
if(window.location.hash) {
    item = window.location.hash;
} else {
    item=-1;
}

then simply pass the item to accordion in your call:

open            : item

I think this is simple enought but I'm not sure if this is actually what you wanted.

于 2013-05-03T20:07:12.033 回答
0

我这样解决了:

        $(function() {
            if(window.location.hash) {
                var hash = window.location.hash;
                var newHashName = hash.replace("#","");
            } else {
                newHashName=-1;
            }

    $('#st-accordion').accordion({
    oneOpenedItem   : true,
            open: newHashName,
            });
        });

但请注意,第一个选项卡始终是0,脚本使用索引(从 0 开始),因此如果您想使用特定 ID,例如名称或帖子 ID,则必须修改脚本本身(我现在还不知道)。

这意味着如果您有帖子,则必须从元素开始添加计数,0并且<li>链接应该是site.com/page/(第一个选项卡),site.com/page/#1(第二个选项卡)等

于 2013-05-05T16:43:01.927 回答