簡體   English   中英

無法讓 jquery 手風琴關閉所有面板

[英]Trouble getting jquery accordion to close all panels

我正在使用手風琴腳本,有些頁面有子頁面(關於,方法,我們的工作),有些沒有。 如果用戶在沒有子菜單的頁面上,我也不希望顯示另一個子菜單(這是當前情況)

網站: http://thegoodgirlsnyc.com/test/new/index3_7.php

header中的jquery:

 ddaccordion.init({
    headerclass: "headerbar", //Shared CSS class name of headers group
   contentclass: "submenu", //Shared CSS class name of contents group
    revealtype: "click", //Reveal content when user clicks or onmouseover the     header? Valid value: "click", "clickgo", or "mouseover"
    mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds    before header expands onMouseover
    collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
    defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
    animatedefault: false, //Should contents open by default be animated into view?
    persiststate: true, //persist state of opened contents within browser session?
    toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
    //do nothing
},
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
    //do nothing
}

})

和js文件: http://thegoodgirlsnyc.com/test/new/js/ddaccordion.js

我想我可以添加一個新的 headerclass -“headerclass2”並將其定義為 headerbar2,因為沒有下拉 class 名稱的菜單項是.headerbar2 並更改實際 js 文件中的行 #37 - 41 說:

collapseall:function(headerclass2){ //PUBLIC function to collapse all headers based on their shared CSS classname
    var $headers=this.headergroup[headerclass2]
    this.contentgroup[headerclass2].filter(':visible').each(function(){
        $headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion")
    })
},

當用戶單擊沒有子菜單的鏈接時,如何關閉所有子菜單?

我認為您遇到的問題是 state 由於設置而被持久化:persiststate persiststate: true,

看起來會發生什么,而不是打開單擊的標題欄(即沙龍)並關閉其他標題欄,它只是直接進入鏈接頁面,因為沒有子菜單。 並且由於您保留 state,因此打開的標題欄在新頁面上保持打開狀態。

所以,我的建議是使用defaultexpanded選項,打開你想在特定頁面上打開的特定標題欄。 然后,您可以關閉persiststate並讓頁面自己處理應該展開的標題欄。 這可能需要更多的工作,但它可以讓您更好地控制在訪問頁面時默認打開哪些菜單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM