ページでアコーディオンのショートコードが正常に機能していますが、コンテンツにアコーディオンの特定のパネルを開きたいリンクがある場合、機能しません。たぶん誰かが私のJSコードを編集するための道に私を導くことができますか?
/**
* Main JavaScript
*/
// Document is loaded...
jQuery(document).ready(function($) {
/******************************************
* ACCORDION (Shortcode)
**************************************/
var accordion_active_class = 'accordion-active';
// Loop each instance
$('.accordion').each(function() {
var accordion_wrapper = this;
var sections = $('> section', accordion_wrapper);
// Make sure only one active section on load
var active_section_set = false;
$(sections).each(function(index) {
// Section is active
if ($(this).hasClass('accordion-active')) {
// Another was already set
if (active_section_set) {
$(this).removeClass('accordion-active'); // hide section
}
// Allow only one active section
active_section_set = true;
}
});
// Click on section
$('.accordion-section-title', sections).click(function() {
var section = $(this).parent();
// if clicked section was not self
if (!$(section).hasClass(accordion_active_class)) {
// hide all section content
$('.accordion-content', sections).hide();
// show current section content
$('.accordion-content', section).hide().fadeTo(500, 1); // fadeTo looks better than fadeIn in IE7
// move active class to new active section
sections.removeClass(accordion_active_class);
$(section).addClass(accordion_active_class);
}
// if it was self, close it
else {
$('.accordion-content', sections).hide();
sections.removeClass(accordion_active_class);
}
});
});
// CSS fixes for IE8 which doesn't support :not or :last-child
$('.accordion section .accordion-content > :last-child').css('margin-bottom', '0');
$('.accordion section:not(.' + accordion_active_class + ') .accordion-content').hide();
// Mysterious IE8 layout bug fix
// http://stackoverflow.com/questions/3350441/dynamic-elements-are-not-appearing-in-ie8-until-there-is-a-mouse-click
$('.accordion section').addClass('dummyclass').removeClass('dummyclass');
});
出力されるHTMLは次のとおりです。
<div class="accordion">
<section id="title1" class="">
<div class="accordion-section-title">Title 1</div>
<div class="accordion-content" style="display: none; opacity: 1;">
<p>This is some text.</p>
</div>
</section>
<section id="title2" class="">
<div class="accordion-section-title">Title 2</div>
<div class="accordion-content" style="display: none; opacity: 1;">
<p>This is some more text.</p>
</div>
</section>
</div>
そして最後に、これは私がドロップダウンをトリガーしたいリンクの構造です:
<a href="#title1">Title 1 - trigger</a>