О, я вижу, Джефф сообщил, что текущая версия пользовательского интерфейса не работает, но у меня действительно было решение, использующее текущую версию ...
HTML
<div id="accordion">
<h3><a href="#branding">Branding</a></h3>
<div>
<p>Does your business have a</p>
</div>
<h3><a href="#print">Print</a></h3>
<div>
<p>Brochures</p>
</div>
</div>
Сценарий
$(function(){
$('#accordion').accordion({
collapsible: true,
animated: 'slide',
autoHeight: false,
navigation: true
});
// open content that matches the hash
var hash = window.location.hash;
var thash = hash.substring(hash.lastIndexOf('#'), hash.length);
$('#accordion').find('a[href*='+ thash + ']').closest('h3').trigger('click');
})
Первоначально я использовал a[href$=...]
, но изменил его на a[href*=...]
... либо будет работать
Обновление: опция navigation
была удалена из jQuery UI 1.10.0 , поэтому используйте этот метод:
CSS
.accordion {
position: relative;
}
.accordion .accordion-link {
position: absolute;
right: 1%;
margin-top: 16px;
z-index: 1;
width: 12px;
height: 12px;
background: url(link.png) center center no-repeat; /* approx 12x12 link icon */
}
Сценарий
var hashId = 0,
$accordion = $('#accordion');
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
}
$accordion.accordion({
active: hashId,
animate: false,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="#' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});