我有一个Accordion按照标记,CSS和jquery与给定相同。我无法建立外部锚点链接(同一页面和其他页面)来触发打开特定面板。手风琴来自模板。
HTML
<!-- Accordions -->
<h1 class="h-margin">Accordions</h1>
<div class="accordion-trigger">Categories</div>
<div class="accordion-container" data-panel="0">
Pellentesque habitant
</div>
<div class="accordion-trigger">Categories</div>
<div class="accordion-container" data-panel="1">
Pellentesque habitant morbi
</div>
<div class="accordion-trigger">Categories</div>
<div class="accordion-container" data-panel="2">
Pellentesque habitant morbi tris
</div>
<!-- ENDS Accordions -->
<a href="#">Open Section 1</a>
<a href="#">Open Section 2</a>
<a href="#">Open Section 3</a>
JavaScript
// Accordion box
$('.accordion-container').hide();
$('.accordion-trigger:first').addClass('active').next().show();
$('.accordion-trigger').click(function(){
if( $(this).next().is(':hidden') ) {
$('.accordion-trigger').removeClass('active').next().slideUp();
$(this).toggleClass('active').next().slideDown();
}
return false;
});
答案 0 :(得分:0)
它会帮助你:
// 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');