0

I have an accordion menu and I can't figure out how to link. The menu itself works fine.

When I click the below link, my first accordion menu should open up

<a href="case_studies.html#case1">Case study 1</a>

JavaScript for the accordion

<script type="text/javascript">
$(document).ready(function(){
 $("a#show-panel").click(function(){
    $("#lightbox, #lightbox-panel").fadeIn(300);
 })
 $("a#close-panel").click(function(){
     $("#lightbox, #lightbox-panel").fadeOut(300);
 })
})
</script>

<script type="text/javascript">
    $(function(){
        $("#accordion-header").accordion({ navigation: true });
     });
</script>

The accordion.js file

$(document).ready(function()
{
    //Add Inactive Class To All Accordion Headers
    $('.accordion-header').toggleClass('inactive-header');

    //Set The Accordion Content Width
    var contentwidth = $('.accordion-header').width();
    $('.accordion-content').css({'width' : contentwidth });

/*  //Open The First Accordion Section When Page Loads
    $('.accordion-header').first().toggleClass('active-header').toggleClass('inactive-header');
    $('.accordion-content').first().slideDown().toggleClass('open-content');   */

    // The Accordion Effect
    $('.accordion-header').click(function () {
        if($(this).is('.inactive-header')) {
            $('.active-header').toggleClass('active-header').toggleClass('inactive-header').next().slideToggle().toggleClass('open-content');
            $(this).toggleClass('active-header').toggleClass('inactive-header');
            $(this).next().slideToggle().toggleClass('open-content');
        }

        else {
            $(this).toggleClass('active-header').toggleClass('inactive-header');
            $(this).next().slideToggle().toggleClass('open-content');
        }
    });

    return false;
});

The Body code for the accordian is

<div id="accordion-container">
    <p class="accordion-header" style="border-top:solid 1px #009edb; border-bottom:solid 1px #009edb;"><span style="padding-left:10px; color:#009edb; padding-top:10px; line-height:25px;"><a href="#case1">Case study 1</a></span></p>

        <div class="accordion-content">
        <div class="textInner">
                TEST TEXT THAT FALLS UNDER THE MENU
                </div>
        </div>

        <p class="accordion-header" style="border-top:solid 1px #009edb; border-bottom:solid 1px #009edb;"><span style="padding-left:10px; color:#009edb; padding-top:10px; line-height:25px;"><a href="#case2">Case study 2</a></span></p>

        <div class="accordion-content">
        <div class="textInner">
                TEST TEXT THAT FALLS UNDER THE MENU
                </div>
        </div>
</div>

Any help is appreciated. I am running out of ideas here.

Cheers and thanks in advance, G

4

2 回答 2

0
 $(function(){
    $("#accordion-header").accordion({ navigation: true });
    $("[href='#case1']").parent('.accordion-header').click();
 });

(我让您自己了解如何从 url 获取哈希值)

编辑:查看您的代码,在您的手风琴插件中使用哈希更改处理程序事件(而不是单击事件)可能也更相关

于 2013-10-08T06:12:40.503 回答
0

在这里拉小提琴!正如我从你的问题中了解到的那样,这很有效。

    <li class="dropdown">
    <a id="drop4" role="button" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
    <ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4">
            <li role="presentation"><a class= "opener" data-panel="0" role="menuitem" tabindex="-1" href="#">Bank</a></li>
            <li role="presentation"><a role="menuitem"class= "opener" data-panel="1" tabindex="-1" href="#">Cash</a></li>
            <li role="presentation"><a role="menuitem" class= "opener" data-panel="2" tabindex="-1" href="#">Property</a></li>          
    </ul>
</li>
    <div id="Accordion">
    <h3>Section 1</h3>
    <div>
        <p></p>
    </div>
<h3>Section 2</h3>
    <div>
       <p></p>
    </div>
<h3>Section 3</h3>
    <div>
       <p></p>
    </div>
<h3>Section 4</h3>
    <div>
        <p>One</p>
        <p>Two</p>
    </div>

它的javascript是:

var $accordion = $("#Accordion");

$accordion.accordion();

$(".opener").on("click", function () {
    var $this = $(this),
        toOpen = $this.data("panel");

    $accordion.accordion("option", "active", toOpen);

    return false;
});
于 2014-02-28T15:09:11.713 回答