See:Activate Accordion Section By URL Hash
Demo:found here.
TL; DR ... Ecco il codice:
$("#accordion").accordion({
// Called when the widget instance is created.
create: function(e, ui) {
// The accordion DOM element.
var $this = $(this);
// Triggered when the browser hash changes.
$(window).on("hashchange", function(e) {
// The selector string used to find all accordion headers.
var headers = $this.accordion("option", "header"),
// The header we're looking for, based on the location hash.
header = $(location.hash),
// The index of the header we're looking for.
index = $this.find(headers).index(header);
// If there's a valid index, activate the accordion section.
// Otherwise, do nothing.
if (index >= 0) {
$this.accordion("option", "active", index);
}
});
// Make sure this works on initial page load.
$(window).trigger("hashchange");
}
});
... e il codice HTML:
<div id="accordion">
<h3 id="section1">Section 1</h3>
<div>
<p>
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
</p>
</div>
<h3 id="section2">Section 2</h3>
<div>
<p>
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
suscipit faucibus urna.
</p>
</div>
<h3 id="section3">Section 3</h3>
<div>
<p>
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3 id="section4">Section 4</h3>
<div>
<p>
Cras dictum. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
mauris vel est.
</p>
<p>
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos.
</p>
</div>
</div>
ha funzionato bene per le mie esigenze!
Qual è il problema? Stai ricevendo un errore, non sembra corretto? –
Non apre la fisarmonica "branding" – Andy
Solo un avvertimento per chiunque stia guardando che l'opzione "navigazione" è stata rimossa in [JQuery UI 1.9] (http://jqueryui.com/upgrade-guide/1.9/#deprecated-)-opzioni di navigazione-e-navigationfilter. Utilizzato per impostare il pannello attivo in base all'URL. Immagino che debba essere stato troppo utile. :( –